Hi, Please help me with this java question. It has three parts. Suppose that we
ID: 663337 • Letter: H
Question
Hi,
Please help me with this java question. It has three parts.
Suppose that we need to develop a simple class called Country for use in a geographical database system. The class will need variables to hold (a) the name of a country, which contains mainly alpha betic characters, (b) its capital city as alphabetic characters, (c) area in square km as a double, and (d) population as an integer. The only constructor for this class requires four arguments, the name, capital, population, and area. The methods needed are getName() which returns the name of the country, getCapital() which returns the name of the capital city, getArea() which returns the area in square km, getPopulation() which returns the population size, and setPopulation(popSize) which changes the size of population to the value popSize. (a) Write out a skeleton of the Country class, clearly showing all variable declarations and method definitions. Their respective types, signatures, and arguments must be included. You are NOT required to include any code in the methods. (2 marks) (b) In an existing Geography class the following method is required: public static String largestCountry(Country[] countryList) It should return the name of the country that has the largest land area. Write out the method in detail. (5 marks) (c) Suppose that we are also interested in finding the country that is most densely populated (i.e., having the most number of people per square km). Write a method public static String mostDenselyPopulatedCountry(Country [] countryList) that returns the name of the most densely populated country. (5 marks)Explanation / Answer
class Country {
String name;
String capital;
double area;
int population;
Country(String name, String capital, double area, int population)
{ }
void setPopulation (int popsize) { }
String getName() { }
String getCapital(){ }
double getArea(){ }
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.