Question: Help with Java !!! This Assigment me going crazy!!! There's another file that i have to insert in this code, its a .csv file (excel).

Help with Java !!! This Assigment me going crazy!!! There's another file that i have to insert in this code, its a .csv file (excel). PLEASE EXPLAIN AND SHOW OUTPUT, AND EXPLAIN WHERE I SHOULD PUT THE .CSV FILE. PLEASE

1. Document the Country class public interface. Use the javadoc utility to produce the class documentation. Use a web browser to view the documentation file generated by the javadoc utility.

2. Complete the TODOs in Lab9CountryDataTester.java and CountryDataLoader.java. Test your changes. You may want to make a change and test it rather that making all the changes and then test all the changes as once. Find a way to incrementally build and test. You may also want to work with a smaller data file during the build and test increments. When all the changes are made and the countryData.csv is the input file the program output looks like this:

Help with Java !!! This Assigment me going crazy!!! There's another file

that i have to insert in this code, its a .csv file

Here's the Code, Country TODO's:

public class Country implements Comparable { private String name; private long population; private double area; public Country() { this("", 0, 0.0); } public Country(String name) { this(name, 0, 0.0); } public Country(String name, long population, double area) { this.name = name; this.population = population; this.area = area; } public String getName() { return name; } public long getPopulation() { return population; } public double getArea() { return area; } public void setPopulation(long population) { this.population = population; } public void setArea(double area) { this.area = area; } public double getPopulationDensity() { double pd = 0.0; if(area > 0.0) { pd = population / area; } return pd; } public String toString() { String s = String.format( "", name, population, area); return s; } public int compareTo(Country other) { if(other == null) { return 1; } int rc = name.compareTo(other.name); if( rc != 0) { return rc; } double popDiff = population - other.population; if(popDiff > 0) { return 1; } if(popDiff  0) { return 1; } if(areaDiff  

Here'sCountry Data Loader Code, TODO's:

import java.io.File; import java.io.FileNotFoundException; import java.util.List; import java.util.Scanner; /** * Complete the TODOs. * */ public class CountryDataLoader { /** * Reads country data from the country data file. Create a Country object * for each line of country data. Stores the Country objects in a List. * * The country data file consists on lines of text. Each line contains * three fields: the country's name, the country's population, and the * country's area. A '|' is used to separate the fields. * * @param countryDataFile * @return List of Country objects * * @throws FileNotFoundException */ public static List load(File countryDataFile ) throws FileNotFoundException { // TODO: // Create an ArrayList of Country objects. Assign the reference to // countryList. List countryList = null; Scanner inpFile = new Scanner(countryDataFile); inpFile.useDelimiter("[| ]"); while(inpFile.hasNextLine()) { String name = inpFile.next(); long population = inpFile.nextLong(); double area = inpFile.nextDouble(); // TODO: // Create a Country object using the name, population, and area // values. Put the Country object in the ArrayList of Country // objects. inpFile.nextLine(); } return countryList; } } 

And Last the Tester, TODO's:

import java.io.File; import java.io.FileNotFoundException; import java.util.List; /** * Lab 9. Interfaces. Complete the TODOs. */ public class Lab9CountryDataTester { /** * This program allows the user to select a country data file and sorts * the country data. * * The country data file consists on lines of text. Each line contains * three fields: the country's name, the country's population, and the * country's area. A '|' is used to separate the fields. Here is a * snippet of the data file: Botswana|2182719|581730.0 Saint Vincent and the Grenadines|102627|389.0 Dominican Republic|10478756|48670.0 Denmark|5581503|43094.0 Mexico|121736809|1964375.0 * * * The country data is sorted in the following ordering: * 1. Natural Order * 2. Descending population (highest to lowest) and ascending name * 3. Descending area and ascending name * 4. Descending population density and ascending name * 5. Reverse Natural Order * * After each sort the program prints the first 10 countries and the last * 10 countries in the ordered list. */ public static void main(String[] args) throws FileNotFoundException { final int PRINT_FIRST_N = 10; final int PRINT_LAST_N = 10; // TODO: Part 1. // Write the code to select the country data file. Create a File // object and assignment the refrence to countryDataFile. File countryDataFile = null; // TODO: Part 2. // Read the country data file into a List of Country objects. // Make the needed changes to CountryDataLoader.load(File). // There is a exception that needs to be handeled. List countryList = CountryDataLoader.load(countryDataFile); // TODO: Part 3. // Sort the List of Country objects by the Country natural ordering. // The Country class implements the Comparable interface. The compareTo // method uses the Natural Order. System.out.println(); System.out.println("Country Data Sorted by Natural Order"); printFirstN(countryList, PRINT_FIRST_N); printLastN(countryList, PRINT_LAST_N); // TODO: Part 4 // Sort the List of Country objects by descending population and // ascending name. You will need to write a class that implements // the Comparator interface. Name the class // PopulationAndNameComparator. System.out.println(); System.out.println("Country Data Sorted by Descending population and " + "Ascending name"); printFirstN(countryList, PRINT_FIRST_N); printLastN(countryList, PRINT_LAST_N); // TODO: Part 5 // Sort the List of Country objects by descending area and // ascending name. You will need to write a class that implements // the Comparator interface. Name the class // AreaAndNameComparator. System.out.println(); System.out.println("Country Data Sorted by Descending area and " + "Ascending name"); printFirstN(countryList, PRINT_FIRST_N); printLastN(countryList, PRINT_LAST_N); // TODO: Part 6 // Sort the List of Country objects by descending population density and // ascending name. You will need to write a class that implements // the Comparator interface. Name the class // PopulationDensityAndNameComparator. System.out.println(); System.out.println("Country Data Sorted by Descending population " + "density and Ascending name"); printFirstN(countryList, PRINT_FIRST_N); printLastN(countryList, PRINT_LAST_N); // TODO: Part 7 // Sort the List of Country objects by reverse natural order. // You will need to use a class that implements the Comparator // interface. // Do not write the class. Use the Collections.reverseOrder() method. // PopulationAndNameComparator. System.out.println(); System.out.println("Country Data Sorted by Reverse Natural Order"); printFirstN(countryList, PRINT_FIRST_N); printLastN(countryList, PRINT_LAST_N); } /** * Print the first N objects in a List * * @param list * @param n */ private static void printFirstN(List list, int n) { int endIdx = Math.min(n, list.size()); for(int k = 0; k  

Country Data Sorted by Natural Order [0] name Afghanistan population 32564342, area 652230.0 [1] name Akrotiri population 0, area: 123.0> [2] name Albania population: 3029278 area 28748.0 [3] name Algeria population: 39542166 area 2381741.0> [4] name American Samoa population: 54343 area 199.0> [5] name Andorra population. 85580 area 468.0 [6] name Angola. population 19625353 area 1246700.0> [7] [9] name Argentina population. 43431886 area: 2780400.0 252 Kname: Venezuela population 29275460, area 912050. 253 area [254] 2601 Country Data Sorted by Descending population and Ascending name 0] [1] [2] [3] 254] 255] 2561 259]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!