Program code Java In the program create 5 additional methods. The main0 will cal
ID: 3603953 • Letter: P
Question
Program code Java
In the program create 5 additional methods. The main0 will call these methods in the order listed for as many oceans as needed. Don't forget to exit the main). Code these methods after the main0. Name and code the methods as follows: setOcean: This method prompts for the ocean and stores it in a variable that the other methods can access. setSize: This method prompts for a descriptive size of the ocean and stores it in a variable accessible to the other methods. A list of descriptive sizes is displayed (see sample output). The user selects from the list. Based on the selection a switch is used to determine the descriptive size: Largest, Second Largest, Third Largest, Fourth Largest, Smallest or display the error message: Try agaln! Re-enter selectlon. Use a do- whlle to re-prompt if the choice is anything less than 1 or greater than 5. There'll be 2 variables: one to store the selection from the list and the other to store the size as "Largest or "Second Largest, etc. The switch uses the first variable to determine the value in the second variable or print the error message. setkilometers(0): This method prompts for the total area of the ocean in kilometers and stores it in a variable accessible to the other methods. calcTotalAreaMilesO This method converts the kilometers into miles using a conversion factor of 0.621 where 1 kilometer = 0.621 miles. printOceaninfoo This method prints the ocean information (see sample output).Explanation / Answer
World5Oceans.java
import java.text.DecimalFormat;
import java.util.Scanner;
public class World5Oceans {
// Declaring static variables
static String oceanName;
static String size;
static double kms;
/*
* Creating an Scanner class object which is used to get the inputs entered
* by the user
*/
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("The 5 World Oceans");
/*
* This while loop continues to execute until the user enters 'N' or 'n'
*/
while (true) {
// calling the methods
setOcean();
setSize();
setKilometers();
printOceanInfo();
// Getting the character from the user 'Y' or 'y' or 'N' or 'n'
System.out.print("Enter another ocean (Y/N) ::");
char ch = sc.next(".").charAt(0);
if (ch == 'Y' || ch == 'y') {
sc.nextLine();
System.out.println("OCEAN FACTS");
continue;
} else {
System.out.println(":: Program Exit ::");
break;
}
}
}
// This method will display the Ocean Info
private static void printOceanInfo() {
// DecimalFormat class is used to format the output
DecimalFormat df = new DecimalFormat(".000");
System.out.println(" OCEANS OF THE WORLD");
System.out.println("Ocean :" + oceanName);
System.out.println("Size :" + size);
System.out.println("Total Square Miles:" + df.format(kms * 0.621) + " million");
System.out.println("OCEANS OF THE WORLD");
}
private static void setKilometers() {
System.out.print("Enter the total area for the " + oceanName + " ocean in kilometers :");
kms = sc.nextDouble();
}
// This method will set the size of the ocean
private static void setSize() {
while (true) {
System.out.println("1.Largest");
System.out.println("2.Second Largest");
System.out.println("3.Third Largest");
System.out.println("4.Fourth Largest");
System.out.println("5.Smallest");
System.out
.print("From the above list ,select the size of an Artic Ocean:");
int choice = sc.nextInt();
switch (choice) {
case 1:
{
size = "Largest";
break;
}
case 2:
{
size = "Second Largest";
break;
}
case 3:
{
size = "Third Largest";
break;
}
case 4:
{
size = "Fourth Largest";
break;
}
case 5:
{
size = "Smallest";
break;
}
default:
{
System.out.println("Try again! Re-enter selection.");
continue;
}
}
break;
}
}
// This method will set the ocean name
private static void setOcean() {
System.out.print("Enter an ocean:");
oceanName = sc.nextLine();
}
}
_________________
Output:
The 5 World Oceans
Enter an ocean:Southern
1.Largest
2.Second Largest
3.Third Largest
4.Fourth Largest
5.Smallest
From the above list ,select the size of an Artic Ocean:4
Enter the total area for the Southern ocean in kilometers :20.327
OCEANS OF THE WORLD
Ocean :Southern
Size :Fourth Largest
Total Square Miles:12.623 million
OCEANS OF THE WORLD
Enter another ocean (Y/N) ::Y
OCEAN FACTS
Enter an ocean:Artic
1.Largest
2.Second Largest
3.Third Largest
4.Fourth Largest
5.Smallest
From the above list ,select the size of an Artic Ocean:6
Try again! Re-enter selection.
1.Largest
2.Second Largest
3.Third Largest
4.Fourth Largest
5.Smallest
From the above list ,select the size of an Artic Ocean:0
Try again! Re-enter selection.
1.Largest
2.Second Largest
3.Third Largest
4.Fourth Largest
5.Smallest
From the above list ,select the size of an Artic Ocean:5
Enter the total area for the Artic ocean in kilometers :14.056
OCEANS OF THE WORLD
Ocean :Artic
Size :Smallest
Total Square Miles:8.729 million
OCEANS OF THE WORLD
Enter another ocean (Y/N) ::n
:: Program Exit ::
_____________Could you rate me well.Plz .Thank You
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.