Question
In Continent.java Declare a public enum called Continent. It includes a constant for each of the 7 continents Remember: According to the Java naming convention
In Continent.java
Declare a public enum called Continent. It includes a constant for each of the 7 continents
Remember: According to the Java naming convention enum constants should be capitalized Continents that consist of two words should use an underscore like NORTH_AMERICA Example: public enum Direction { UP, DOWN, LEFT, RIGHT }
. . . Compile and run
In Country.java
In the fields section Create the following two fields:
A private final field of type String called name
A private final field of type Continent called continent
In the constructor section: Create one constructor that takes two parameters. Initialize the private fields with the values passed in the parameters
In the methods section: Add the following two getters above the toString method that is already declared:
getName returns the value of the field name
getContinent returns the value of the field continent
In method toString delete the statement return null; and replace it with the following statement:
return String.format("%s (%s)", name, continent);
. . . Compile and run
In CountryTest.java Un-comment the three print statements in the main method. At the beginning of the main method before the print statements do the following:
an instance of type Continent called myContinent. Initialize it with NORTH_AMERICA
an instance of type Country called country1. Initialize it with the name USA and the variable myContinent
an instance of type Country called country2. Initialize
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