Question: public class Country { //-----------Start below here. To do: approximate lines of code = 14 /** * Create 3 instance variables: one of type String

public class Country { //-----------Start below here. To do: approximate lines of code = 14 /** * Create 3 instance variables: one of type String to store the * country name, one of type int to store the population and one of * type double to store the area */ /** Create a constructor method that has 3 parameters, one to initialize the name, one to initialize the population and one to initialize the area */

/** Create a public method getCountryStats() that returns a String containing the name of the country followed by the population followed by the area. See the tester code as a guide. */ /** Create a public method getPopulationDensity() that returns a double number representing the population density. Make sure to check that area is > 0 before dividing population by it */ //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. }

// Tester class that helps test the code

public class CountryTester { public static void main(String[] args) { Country canada = new Country("Canada",35000000,9985000); Country france = new Country("France",66000000,643800); // Expected Output: // Name: Canada Population 35000000 Area 9985000.0 Density 3.5052578868302455 // Name: France Population 66000000 Area 643800.0 Density 102.51630941286113

System.out.println("" + canada.getCountryStats() + " Density " + canada.getPopulationDensity()); System.out.println("" + france.getCountryStats() + " Density " + france.getPopulationDensity()); } }

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!