Implement a class called countrycatalogue

Assignment Help Python Programming
Reference no: EM131750414

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.

TASK 1

Implement a class Country that holds the information about a single country; name the file country.py.

Instance Variables

1) name: The name of the country (string)
2) population: The population in the country (integer)
3) area: The area of the country (float)
4) continent: The name of the continent to which the country belongs (string)

Methods

1) Constructor, __init__(self, name, pop, area, continent)

2) Getter Methods: getName, getPopulation, getArea, getContinent,

3) Setter Methods: setPopulation, setArea, setContinent

4) getPopDensity: This calculates and returns the population density for the country. Population density is the population divided by the area rounded to 2 decimal places.

5) def __repr__(self): generates a string representation for class objects.

Test all your classes and methods before moving to the next section. Feel free to create other helper methods if necessary.

TASK 2

Implement a class called CountryCatalogue; name the file catalogue.py

This class will use two files to build the data structures to hold the information about countries and continents. The file data.txt contains information about a number of countries and the file continent.txt contains information about countries and continents.

This class should have the following two instance variables:

1. countryCat: This is a collection of countries, i.e., each member is an object of the class Country. The collection could be a set, dictionary or list. It is important that the collection store objects of type Country.

2. cDictionary: This is a dictionary where the key is the country name and the value is the name of the continent. You may add other instance variables as you see fit.

METHODS

1. Constructor: The constructor method will take as parameters two files:

• the first one is the name of the file that contains the names of countries and continents
• the second is the name of the file that contains the country information

The constructor will use the data in the files to construct the two data structures countryCat and cDictionary. It does this as follows:

1. Fill the Dictionary: Using the first file, fill cDictionary; the key is the country name, while the name of the continent is the value.

2. Fill the Catalogue: Using the second file, read each line of the file and from that create a country and add it to countryCat. (Note: you will also need to use the data in cDictionary to determine the continent for each country)

Sample data files has been included: continent.txt and data.txt

Notes: a) Both files have headers and b) these files are meant for you to test your program; they may NOT be the same used to evaluate your solution.

2. findCountry: This method allows a user to look up information on countries. It takes as a parameter a country name and checks the catalog. If the operation is successful (i.e., if the country exists in the catalog), the method should return the country object, if it is not successful the method should return null object (i.e., None).

3. setPopulationOfCountry: This method will take as parameters a country name and new population and then set the population of the country (if it is in the catalogue) to the value. The method should return True if the operation is successful, or False if it is not, e.g. the country is not in the catalogue.

4. setAreaOfCountry: This method will take as parameters a country name and a new area and then set the area of the country (if it is in the catalogue) to the value. The method should return True if the operation is successful, or False if it is not, e.g. the country is not in the catalogue.

5. addCountry: This method provides a way to add a new country to the dictionary of countries and country catalogue. The method takes as parameters the country name, population, area and continent of the country. The method should return True if the operation is successful (country successfully added), or False if it is not, e.g. the country they entered already exists. In addition to adding the newly created country to the country catalogue, make sure you add the country and continent to the cDictionary.

6. deleteCountry: This method will take as parameter a country name and then if this country exists then it should be deleted from the catalogue and from cDictionary. If the country does not exist, no further action is needed. (This method doesn't return anything).

7. printCountryCatalogue: This method displays the whole catalogue to the screen, using the default string representation for the Country objects.

8. getCountriesByContinent: This method will return a list of countries on a specific continent. This method takes as a parameter the name of a continent. If the parameter is the name of a valid continent, then it will return a list of the countries on that continent, otherwise it returns an empty list. (Note: the return type is list and the elements of the list are Country objects)

9. getCountriesByPopulation: This method will return a list of pairs (tuples) where pair is a country and their population. The list should be in descending order by population from the largest to the smallest. This method takes as a parameter the name of a continent as input or takes nothing at all (default is the empty string). If the parameter is the name of a valid continent, then it will return a list of only the countries and their population on that continent - by population from largest to smallest. If the continent name is the default, then it will return a list of all the countries and their population in the catalogue. For an input value that is not a continent, it returns an empty list.

10. getCountriesByArea: This method will return a list of pairs (tuples) where each pair is a country and their area (just the value, no units). The list should be in descending order by area from the largest to the smallest. This method takes as a parameter the name of a continent as input or takes nothing at all (default is the empty string). If the parameter is the name of a valid continent, then it will return a list of only the countries and their areas on that continent - sorted by area from largest to smallest. If the continent name is the default, then it will return a list of all the countries and their areas in the catalogue (once again sorted by area). For an input value that is not a continent, it returns an empty list.

11. findMostPopulousContinent: This method will find and return the name of the continent with the most number of people living in it and the number of people living in the continent. This should return a tuple (continent name, population of continent). You cannot assume that the continent names are fixed, therefore you must first determine what are the continents that exist in your dataset.

12. filterCountriesByPopDensity: This method will take as parameters as a lower bound and upper bound for a population density range and then return a list of countries that have a population density that falls within the range (inclusive of the endpoints). It should return a list of pairs, where each pair is a country name and a population density. The list should be descending order from the highest density to the lowers. If there are no countries with population density within the range, it should return an empty list.

13. saveCountryCatalogue: This method will enable all the country information in the catalogue to be saved to a file. The method takes as a parameter the name of the file. All the countries should be sorted alphabetically by name (A - Z) prior to saving.

Note: no spaces between attributes, 2 decimal places for the area and the population density. If the operation is successful, the method should return the number of items written, otherwise it should return a value of -1.

You may add other methods as you see fit.

Test all your classes and methods before moving to the next section. Feel free to create other helper methods if necessary.

Use the main.py file provided as the interface to your program. It has been designed to call the methods of the classes as named above; make sure that you use these names. You may use the functions in main.py to test your program in other ways. The TA will use a program similar main.py to grade your assignment.

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. Readability: indentation, white space, consistency

Submit the files in which your classes are defined. The name of the file for the Country class should be country.py and the name of the file for the CountryCatalogue class should be catalogue.py.

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

Make sure that you develop your code with Python 3.6 as the interpreter. TAs will not endeavor to fix code that uses earlier versions of Python.

What You Will Be Marked On:

1. Functional specifications:

• Does the program behave according to specifications?
• Does it run when tested with a program similar to 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.

Reference no: EM131750414

Questions Cloud

Management systems-styles work well to support innovation : What particular elements of each organization’s culture, processes, and management systems and styles work well to support innovation?
Depreciation schedule using the straight-line method : Prepare a depreciation schedule using the straight-line method, then enter the accumulated depreciation at the end of year
What cost flow assumption is used to determine cost basis : What cost flow assumption is used to determine cost basis when only a portion of the subsidiary shares are sold
What are the differences among onsite team-virtual team : What are the differences among an onsite team, a virtual team, a task force, and a committee?
Implement a class called countrycatalogue : Implement a class called CountryCatalogue. Implement a class Country that holds the information about a single country; name the file country.py.
Calculate the increase in return available to the investor : Firms U and L are identical in every respect except that the former is not levered, whereas the latter has $2,000,000 in 14-percent debentures outstanding.
Magnotti floors purchased a floor sander : Magnotti Floors purchased a floor sander for $3,550. Delivery costs totaled $225. The salvage value is $755 after 8 years
Talk about the decline of people face to face communication : In order to access the databases through the library you must either be on-campus or connect through the VPN. You can go here to connect.
Efficient means of reducing household poverty : Do you think the minimum wage law is an economically efficient means of reducing household poverty?

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd