Ask Question
25 June, 08:38

Assume that minutes is an int variable whose value is 0 or positive. Write an expression whose value is "undercooked" or "soft-boiled" or "medium-boiled" or "hard-boiled" or "overcooked" based on the value of minutes. In particular: if the value of minutes is less than 2 the expression's value is "undercooked"; 2-4 would be a "soft-boiled", 5-7 would be "medium-boiled", 8-11 would be "hard-boiled" and 12 or more would be a "overcooked".

+3
Answers (1)
  1. 25 June, 11:01
    0
    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Assume that minutes is an int variable whose value is 0 or positive. Write an expression whose value is "undercooked" or "soft-boiled" or ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers