Question
WRITE IN JAVA : Create a class Country with following attributes: private String code; private String name; private String continent; private List cities; Create class
WRITE IN JAVA :
Create a class Country with following attributes:
private String code;
private String name;
private String continent;
private List
Create class City with following attributes:
private int id;
private String name;
private int population;
private String countryCode;
Generate parametrized constructors and getters and setters for all classes
In the main method initialize list of countries with following example values:
Country name: Netherlands, Continent: Europe, County code: NLD
Cities:
City name: Amsterdam, City population: 731200
City name: Rotterdam, City population: 593321
City name: Haag, City population: 440900
***********************************************************************************
Country name: Germany, Continent: Europe, County code: DEU
Cities:
City name: Berlin, City population: 3386667
City name: Hamburg, City population: 1704735
City name: Munich, City population: 1194560
***********************************************************************************
Country name: United States, Continent: North America, County code: USA
Cities:
City name: New York, City population: 8008278
City name: Los Angeles, City population: 3694820
City name: Chicago, City population: 2896016
***********************************************************************************
Country name: Armenia, Continent: Asia, County code: ARM
Cities:
City name: Yerevan, City population: 1248700
***********************************************************************************
Country name: Argentina, Continent: South America, County code: ARG
Cities:
City name: Buenos Aires, City population: 2982146
***********************************************************************************
Country name: Brazil, Continent: South America, County code: BRA
Cities:
City name: Rio de Janeiro, City population: 5598953
Using java stream create a program that will:
print the countries' details as shown above
print all the continents (without duplicates)
print all the country names from North America and South America (only country titles, not the whole objects)
The output should look like this:
City name: Berlin, City population: 3386667 City name: Hamburg, City population: 1704735 City name: Munich, City population: 1194560 Country name: United States, Continent: North America, County code: USA Cities: City name: New York, City population: 8008278 City name: Los Angeles, City population: 3694820 City name: Chicago, City population: 2896016 Country name: Armenia, Continent: Asia, County code: ARM Cities: City name: Yerevan, City population: 1248700 Country name: Argentina, Continent: South America, County code: ARG Cities: City name: Buenos Aires, City population: 2982146 Country name: Brazil, Continent: South America, County code: BRA Cities: City name: Rio de Janeiro, City population: 5598953 Printing all distinct continents: Europe North America Asia South America Printing all countries in South America and North America [United States, Argentina, Brazil] Cities in USA have population of 14599114 citizens
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