Ask Computer Engineering Expert

Assignment

Learning Outcomes:

By completing this assignment, you will gain skills relating to Strings and text files Writing your own classes Testing code Using complex data structures (i.e., sets and dictionaries)

In this assignment you will create a complete program that uses classes to store, search, sort, remove, and filter country data. The two major tasks are outlined below.

1. Implement a class Country Instance Variables:

i. Name: string

ii. Population: integer

iii. Area: float

iv. Continent: string Methods:

i. constructor

ii. Getter Methods: getName, getPopulation, getArea, getContinent,

iii. getPopDensity: This calculates and returns the population density for the country. Pd is the population divided by the area.

iv. Setter Methods: setPopulation

v. def __repr__(self):generate a string representation for the class Name in Continent

e.g China in Asia In addition add a method save that writes the appointment to file object (not file name) in the specified format : Name|Continent|Population|PopulationDensity

For example China|Asia|1000000|4.56 class Country :

def __init__(self, name, pop, area, continent) :

def __repr__(self):

def setPopulation(self, pop):

def getName(self) :

def getArea(self) :

def getPopulation(self) :

def getContinent(self):

def getPopDensity(self) :

def save(self, outobject) : Test all your classes and methods before moving to the next section. Feel free to create other

helper methods if necessary. Write a test file that will also be submitted with this assignment

(test.py)

2. Implement a class called CountryCatalogue that is a set or dictionary or lists of countries.

This class has two instance variable catalogue and cDictionary

This class will have the following methods. Constructor: this method will open the specified file and then first create the

cDictionary and then create countries and add them to the cSet.

Major Steps

1. Fill the Dictionary: open the continent.txt file and fill the cDictionary.

The key is the country name, while the continent is the value.

2. Fill the Catalogue: Open the file (the file name is passed into the

constructor). Then read each line of the file and from that create a

country and add it catalogue.

A sample data file has been included data.txt (Note that both files have headers) addCountry: Give the user the option to add a new country to the set.

Using user input the user must specify the name, population, area and continent. If the country they entered already exists, let them know they can't add a country already in the catalogue and keep on prompting for input until a unique name has been entered. In addition to adding the newly created country to the catalogue, make sure you add the continent to the cDictionary. Include a confirmation message to let the user know whether the operation was successful or not. saveCountryCatalogue: allow the user to save all the countries to a file. This method MUST call the save method for the Country class. Before saving the catalogue sort the countries alphabetically by name. Include a confirmation message to let the user know that it was saved to the specified file. deleteCountry: allows the user to enter a specific countryName, if this country exists then it should be deleted from the catalogue. Include a confirmation message to let the user know whether or not it was deleted. findCountry: allows the user to enter a specific countryName, if this country exists then print all of the country's information to the output screen. If the country does not exist send a message as well. filterCountriesByContinent: allow the user to enter a specific continent (assume valid continent), print to the screen all the countries (just their names) in the catalogue that are in that continent.

printCountryCatalogue: print the whole catalogue to the screen, using the default print for the Country Class setPopulationOfASelectedCountry: Ask the user for a country name and new population and then set the population of the country (if it is in the catalogue) to the value. Print the new population density for that country to the screen. findCountryWithLargestPop: find and display the name of the country with the largest population to the screen findCountryWithSmallestArea: find and display the name of the country with the smallest area to the screen.

filterCountriesByPopDensity: ask the user to enter the lower bound and upper bound for a population density range and then find all countries that have a population density that falls within the range. Assume valid input of integers.

findMostPopulousContinent: find and display the name of the continent with the most number of people living in it. Also display the number of people living in the continent.

class CountryCatalogue:

def __init__(self, filename):

def filterCountriesByContinent(self):

def printCountryCatalogue(self):

def findCountry(self):

def deleteCountry(self):

def addCountry(self):

def setPopulationOfASelectedCountry(self):

def saveCountryCatalogue(self, filename):

def findCountryWithLargestPop(self):

def findCountryWithSmallestArea(self):

def findMostPopulousContinent(self):

def filterCountriesByPopDensity(self): Test your countryCatalogueClass to make sure all functionality is working. Save your test code in test.py

Use the main.py file provided as the interface to your program. The TA will use a similar main.py to grade your assignment. DO NOT EDIT THIS FILE AT ALL

For output to both the console and file you do not need to format numbers to include commas. (e.g 1000 does NOT need to be written as 1,000)

You may assume all the data is correct and there are no errors relating to the data file (so don't worry about Exceptions or validating input except where otherwise noted for this assignment). Non-functional Specifications:

1. Include brief comments in your code identifying yourself, describing the program, and describing key portions of the code.

2. Assignments are to be done individually and must be your own work. Software may be used to detect cheating.

3. Use Python coding conventions and good programming techniques, for example:

i. Meaningful variable names

ii. Conventions for naming variables and constants

iii. Use of constants where appropriate

iv. Readability: indentation, white space, consistency Submit two files one file that includes both classes the filename should be countryGalore.py. Also include a test file named test.py that shows how you tested your classes.

Make sure you attach your python files to your assignment; DO NOT put the code inline in the textbox.

Make sure that you develop your code with Python 3.5 as the interpreter. TAs will not endeavor to fix

code that uses the Python 2.7 or 2.10 conventions.

What You Will Be Marked On:

1. Functional specifications: Does the program behave according to specifications? Does it run with the main program provided? Are your classes created properly? Are you using appropriate data structures? Is the output according to specifications?

2. Non-functional specifications: as described above

3. Assignment submission: via OWL assignment submission.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92063852
  • Price:- $40

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As