Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Youve been given the task to display certain population data for the United States, Germany, and Argentina. You will prompt the user for US data.

Youve been given the task to display certain population data for the United States, Germany, and Argentina. You will prompt the user for US data. For Germany and Argentina, you will send the specified data to the class via overloaded constructor. Create the following in your program: A class named Population that has the following data fields with appropriate modifiers and data types: String variable for name of country. Integer variables for number of males and for number of females. Double variable for number of square miles Integer variable for number of states. The Population class should also contain: Default constructor (no default values). Overloaded constructor that accepts name, males, females, square miles, and states as arguments setters & getters for all data fields. value-returning instance method that calculates total population (males + females) value-returning instance method that calculates population per square mile (population / square miles) value-returning instance method that calculates population per state (population / states). overridden toString method that displays country name, total population, population per square mile, and population per state o display total population, population per square mile, and population per state by accessing the appropriate instance method. The main method should: create an object of the Population class for USA and initialize only the name either by using an additional overloaded constructor or by using the setter. Get user input for USA data (see sample output): number of males, number of females, square miles, number of states and then initialize the object using setters (do not use constructors to populate). Create and initialize objects of the Population class using the overloaded constructor as follows o Germany: males = 40,340,771; females = 41,961,693; square miles = 137,846.52; states = 16 o Argentina: males = 19,768,407; females = 20,643,969; square miles = 1,068,301.76; states = 23. Call the class method (toString) to display the output for each object as noted in sample output. Formatting: total population should be a whole number (no decimal) and comma separated. Population per square mile and population per state should be formatted as comma separated and to two decimal places.

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_2

Step: 3

blur-text-image_3

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

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions

Question

What is the group trying to achieve?

Answered: 1 week ago