In this assignment, you will need to design and implement a class Country (Country.java) that stores the name of the country, its population, and its area. Then write a program (LargestCountry.java) that reads countries from a “coutrydata.txt” and prints • The country with the largest area. • The country with the largest population. • The country with the largest population density (people per square mile). To make it concrete, the followings are the suggested tasks you need to perform: 1.1 Country Class In the first file Country.java, create a class named Country that models a country. It should contain at least the followings (However, you can add any other methods if you like): • Private instance variables name, population, and area; • A constructor takes all three inputs (the name, population and area); • Three getter methods to return each of three instance variables (accessor method); • One getter method to return country population density (accessor method); • Three setter methods to change each of three instance variables (mutator); • A method printCountry that prints out the country information. 1 1.2 LargestCountry Class In the second file LargestCountry.java, you are required to write methods for reading country data, and finding required information. The followings are suggested methods that you need to implement: • Method 1: readCountry /** Reads a country in from a file. @return all countries in an arraylist */ public static ArrayList readCountry(String fileName) throws FileNotFoundException { // your work here } • Method 2: countryWithLargestArea /** @return the country with the largest area */ public static Country countryWithLargestArea( ArrayList countries) { // your work } • Method 3: countryWithLargestPopulation /** @return the country with the largest population */ public static Country countryWithLargestPopulation( ArrayList countries) { // your work } • Method 4: countryWithLargestPopulationDensity /** @return the country with the largest population density */ public static Country countryWithLargestPopulationDensity( ArrayList countries) { // your work } 2 In your main() method in LargestCountry.java, you will use the methods you have implemented to do the following: (1) Read the “coutrydata.txt” in; (2) Print out your findings (See a sample output in Figure 1).
In this assignment, you will need to design and implement a class Country (Country.java) that stores the name of the country, its population, and its area. Then write a program (LargestCountry.java) that reads countries from a “coutrydata.txt” and prints • The country with the largest area. • The country with the largest population. • The country with the largest population density (people per square mile). To make it concrete, the followings are the suggested tasks you need to perform: 1.1 Country Class In the first file Country.java, create a class named Country that models a country. It should contain at least the followings (However, you can add any other methods if you like): • Private instance variables name, population, and area; • A constructor takes all three inputs (the name, population and area); • Three getter methods to return each of three instance variables (accessor method); • One getter method to return country population density (accessor method); • Three setter methods to change each of three instance variables (mutator); • A method printCountry that prints out the country information. 1 1.2 LargestCountry Class In the second file LargestCountry.java, you are required to write methods for reading country data, and finding required information. The followings are suggested methods that you need to implement: • Method 1: readCountry /** Reads a country in from a file. @return all countries in an arraylist */ public static ArrayList readCountry(String fileName) throws FileNotFoundException { // your work here } • Method 2: countryWithLargestArea /** @return the country with the largest area */ public static Country countryWithLargestArea( ArrayList countries) { // your work } • Method 3: countryWithLargestPopulation /** @return the country with the largest population */ public static Country countryWithLargestPopulation( ArrayList countries) { // your work } • Method 4: countryWithLargestPopulationDensity /** @return the country with the largest population density */ public static Country countryWithLargestPopulationDensity( ArrayList countries) { // your work } 2 In your main() method in LargestCountry.java, you will use the methods you have implemented to do the following: (1) Read the “coutrydata.txt” in; (2) Print out your findings (See a sample output in Figure 1).
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 7 images