Answer:
import java.util.Scanner;
public class Solution {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter your minute:");
int minute = scan.nextInt();
switch(minute){
case 0:
case 1:
System.out.println("undercooked");
break;
case 2:
case 3:
case 4:
System.out.println("soft-boiled");
break;
case 5:
case 6:
case 7:
System.out.println("medium-boiled");
break;
case 8:
case 9:
case 10:
case 11:
System.out.println("hard-boiled");
break;
case 12:
System.out.println("overcooked");
break;
default:
if(minute > 12){
System.out.println("overcooked");
} else if (minute < 0){
System.out.println("Enter a valid minute.");
}
}
}
}
Explanation:
The first line is the import statement, which import the Scanner class for receiving user input. The next line is the class declaration which is named Solution.
The Scanner object is declared and assigned as scan. Then a prompt is displayed to the user asking the user to enter the minute. The user input is stored as minute.
Switch statement is use to categorize the user input. If the user enter 0-1, an output of undercooked is displayed. If the user enter 2-4, an output of soft-boiled is displayed. If the user enter 5-7, an output of medium-boiled is displayed. If the user enter 12 or any number above 12, an output of overcooked is displayed. Again, the user enter a number less than zero, an error message is displayed telling the user to enter a valid number.