Question
Lab 05 - Countries Youve been given the task to display certain population data for any country, Japan, and Italy. You will prompt the user
Lab 05 - Countries Youve been given the task to display certain population data for any country, Japan, and Italy. You will prompt the user for the first countrys data. For Japan and Italy, you will send the specified data to the class via overloaded constructor. Create the following in your program: A class named CountryData that has the following data fields with appropriate access modifiers and data types: name of country number of males and for number of females number of square miles number of states The CountryData class should also contain (all with appropriate access modifiers): no-arg constructor (no default values) overloaded constructor that accepts name (optional) 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 (no formulas in the toString) A separate driver class named DriverCountry contains the main method which should: create an object of the CountryData class for Israel and initialize only the name either by using an additional overloaded constructor or by using the setter get user input for Israel 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 CountryData class using the overloaded constructor with data as follows o Japan: males = 61,466,113; females = 64,737,970; square miles = 145,925.123; states = 47 o Italy: males = 26,691,167; females = 30,947,964; square miles = 116,350.4567; states = 20 call the class method (implicitly or explicitly call the 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. *NOTE: for those already familiar with Java programming, please keep this simple: no classes, no try/catch, no exceptions, no GUI, etc. Use only the concepts discussed in Chapters 1 - 9 and in the class demos up to this point. Before starting this lab, be sure to refer to the How to Submit Assignments document in eLearn for proper zipping, documentation, indention, naming conventions, etc. Points may be deducted if submitted incorrectly. REMINDER: Any sources you use besides the textbook or the instructor must be documented in your program with details such as URL. Required project name: LastnameFirstname05 Required package name: chap09 Required class names: as indicated above Sample output using Israel statistics (user input is in green text): What is the name of the country: Israel Israel number of males: 4668451 Israel number of females: 4695549 Israel number of square miles: 8019.2345 Israel number of states: 6 Country: Israel Total Population: 9,364,040 Population per Square Mile: 1,167.70 Population per State: 1,560,673.33 Country: Japan Total Population: 126,204,083 Population per Square Mile: 864.86 Population per State: 2,685,193.26 Country: Italy Total Population: 57,639,131 Population per Square Mile: 495.39 Population per State: 2,881,956.55 Helpful Notes: Use appropriate access modifier, private vs public vs default, especially in data fields. Be sure to include a no-arg constructor AND at least one overloaded constructor. Include ALL getters and setters. The toString is always overridden since it's being inherited from Object.toString. Your program contains 2 separate files: CountryData.java and DriverCountry.java The driver class displays the objects by calling the toString in the CountryData class. Points will be deducted for hardcoding "Israel" in the driver program. Instead, use the getter for the name data field. Formatting can be implemented with printf, String.format(), DecimalFormat, or NumberFormat. Be sure to use comma separation in all numbers and 2 decimal places where appropriate. Be sure you always include comments and proper indentation through the project. Reread the assignment and run the sample output (as well as your own test cases) to confirm all requirements have been met. Male/Female Population source: https://countrymeters.info/en/ Square Miles source
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started