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:
Create an instance of type Continent called myContinent. Initialize it with NORTH_AMERICA
Create an instance of type Country called country1. Initialize it with the name USA and the variable myContinent
Create an instance of type Country called country2. Initialize it with the name Austria and the Continent EUROPE Code to print country1 and country 2 is already provided . . . Compile and run
1 public class Country 2 { 3 // fields 4 5 // constructor 6 7 // methods 8 9 @Override 10 public String toString() 11 { 12 return null; 13 } 14 }
1 public class CountryTest 2 { 3 public static void main(String[] args) 4 { 5 6 // System.out.printf("MyContinent: %s%n", myContinent); 7 // System.out.printf("Country1: %s (%s)%n", country1.getName(), country1.getContinent()); 8 // System.out.printf("Country2: %s (%s)%n", country2.getName(), country2.getContinent()); 9 } 10 }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
