rite a program to perform time conversion. The user will select from the following menu: Hours to minutes Days to hours Minutes to hours Hours to days. Each choice has a separate method which is called when the user makes the selection. Please see the output below: Hours to minutes. 2. Days to hours. 3. Minutes to hours. 4. Hours to days. Enter your choice: 2 Enter the number of days: 5 There are 120 hours in 5 days.

Respuesta :

Answer:

import java.util.Scanner;

public class TimeConversion

{

public static void main(String[] args) {

   

    Scanner input = new Scanner(System.in);

           

       System.out.print("1. Hours to minutes\n2. Days to hours\n3. Minutes to hours\n4. Hours to days\n");

       System.out.print("Enter your choice:");

       int choice = input.nextInt();

       

       switch(choice) {

           case 1:

               System.out.print("Enter the number of hours:");

               int hour = input.nextInt();

               System.out.println("There are "+ hour*60 + " minutes in " + hour + " hours");

               break;

           case 2:

               System.out.print("Enter the number of days:");

               int day = input.nextInt();

               System.out.println("There are "+ day*24 + " hours in " + day + " days");

               break;

           case 3:

               System.out.print("Enter the number of minutes:");

               int minute = input.nextInt();

               System.out.println("There are "+ minute/60 + " hours in " + minute + " minutes");

               break;

           case 4:

               System.out.print("Enter the number of hours:");

               int h = input.nextInt();

               System.out.println("There are "+ h/24 + " days in " + h + " hours");

               break;

           default:

               System.out.println("Invalid Input!");

       }

}

}

Explanation:

- Print the menu

- Ask the user to choose one of the options

- Depending on the choice, use switch-case statement to calculate and print required conversion

- Print an error message if the user enters a number that is not in the menu