Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

* countries.txt Palestine 27000 5 Jordan 89000 10 Egypt 1000000 100 France 643000 65 China 9570000 14000 ********************************************* * Country.java public class Country { private

image text in transcribedimage text in transcribed

* countries.txt

Palestine 27000 5 Jordan 89000 10 Egypt 1000000 100 France 643000 65 China 9570000 14000 *********************************************

* Country.java

public class Country { private String name; private int area; private int population;

public Country(String name, int area, int population) { this.name = name; this.area = area; this.population = population; }

public String getName() { return name; }

public void setName(String name) { this.name = name; }

public int getArea() { return area; }

public void setArea(int area) { this.area = area; }

public int getPopulation() { return population; }

public void setPopulation(int population) { this.population = population; }

@Override public String toString() { return "Country [name=" + name + ", area=" + area + ", population=" + population + "]"; }

}

Suppose we have the following data about countries in a text File (countries.txt). Name Area Population (in Millions) Palestine 27000 5 Jordan 89000 10 Egypt 1000000 100 France 643000 65 China 9570000 14000 The file countries.txt contains data about countries. Each line in the file contains country's name followed by two int numbers: area and population. 1- Define comparator class (CountryPopulation Comparator) used to compare the Country objects according to the population field (Hint: see the lecture 28 to know how to define comparator for a given class). 2- Define comparator class (CountryAreaComparator) used to compare the Country objects according to the area field 3- Write Java Program (MainProgram class) to do the following: . Read the given text (countries.txt) file line by line and represent each line data as an object of the Country Class. Store these Country Objects in a suitable collection (Hint: you can use Tree Set with Comparator). Print out the country objects ordered by the Population field. Print out the country objects ordered by the area field. . Submitting: Submit all files, as a zip file through Moodle, be sure that your submission uses exactly those names. . Country.java CountryPopulation Comparator.java CountryAreaComparator.java Main Program.java

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Design A Practical Approach

Authors: Marilyn Campbell

1st Edition

1587193175, 978-1587193170

More Books

Students also viewed these Databases questions

Question

Explain the importance of Human Resource Management

Answered: 1 week ago

Question

Discuss the scope of Human Resource Management

Answered: 1 week ago

Question

Discuss the different types of leadership

Answered: 1 week ago

Question

Write a note on Organisation manuals

Answered: 1 week ago