Question
Code to help start and work off of is below. What is the complete code for the 3 files? Country.java, Continent.java, and CountryTest.java public class
Code to help start and work off of is below. What is the complete code for the 3 files? Country.java, Continent.java, and CountryTest.java
public class Country
{
// fields
// constructor
// methods
@Override
public String toString()
{
return null;
}
}
--------------------------------------------------------------------------------
public class CountryTest
{
public static void main(String[] args)
{
// System.out.printf("MyContinent: %s%n", myContinent);
// System.out.printf("Country1: %s (%s)%n", country1.getName(), country1.getContinent());
// System.out.printf("Country2: %s (%s)%n", country2.getName(), country2.getContinent());
}
}
Lab Country 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 runStep 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