Question
***JAVA*** Create a Country class with the following: instance variables name, continent, capital (all String), and population (long) a Country constructor with four parameters. There
***JAVA***
Create a Country class with the following: instance variables name, continent, capital (all String), and population (long)
a Country constructor with four parameters. There can be NO negative value for the population instance variable. Use 0 as the default value if the population parameter is invalid.
get and set (accessor and mutator) methods for each instance variable. There can be NO negative value for the population instance variable so be sure to validate the parameter in the setPopulation method. Do NOT update the instance variable if the parameter is invalid (negative). Do NOT use exception handling. a toString method that returns a String with the countrys name, continent, capital, and population, ALL clearly labeled. Use the String.format method. Format the population to use commas for numbers greater than 999.
Create a CountryTest program with the following. an array (data type Country) named countries that has size (length) 6 5 Country objects must be created with existing data (see links below) and placed in the array. You MUST choose one country from each continent: Asia, Americas, Europe, Africa, and Oceania. The sixth Country object must be created with user input (any continent). Place it last in the array.
Use these sites for country info: https://en.wikipedia.org/wiki/List_of_countries_by_population_(United_Nations) (Links to an external site.)Links to an external site.
https://www.thoughtco.com/capitals-of-every-independent-country-1434452 (Links to an external site.)Links to an external site.
use an enhanced for loop to display the info of each Country object in the array, clearly labeled. Do this by calling the toString method.
use the command prompt window (terminal) for input and output
Do NOT use the countries shown in the sample program run below.
Sample program run:
Enter country name: Japan Enter continent: Asia Enter capital: Tokyo Enter population: 127,484,450 Country: Brazil Continent: Americas Capital: Brasilia Population: 209,288,278 Country: Netherlands Continent: Europe Capital: Amsterdam; The Hague (seat of government) Population: 17,035,938 Country: Taiwan Continent: Asia Capital: Taipei Population: 23,626,456 Country: Swaziland Continent: Africa Capital: Mbabane Population: 1,367,254 Country: Fiji Continent: Oceania Capital: Suva Population: 905,502 Country: Japan Continent: Asia Capital: Tokyo Population: 127,484,450 Programmed by Your Name
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