Question

In: Computer Science

JAVA: Write a program to perform time conversion. The user will select from the following menu:...

JAVA:

Write 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.

Solutions

Expert Solution

Program:

import java.util.Scanner;

class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in); // Scanner class declaration

int choice=0; // variable declaration

System.out.println("1 Hours to minutes");

System.out.println("2 Days to hours");

System.out.println("3 Minutes to hours");

System.out.println("4 Hours to days");

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

choice=sc.nextInt(); // Accept the choice from the user

switch(choice) // switch case to select the choice

{

case 1:hoursToMinutes(); // If you want to choose hours to minutes conversion

break;

case 2:daysToHours(); // If you want to choose days to hours conversion

break;

case 3:minutesToHours(); // If you want to choose minutes to hours conversion

break;

case 4:hoursToDays(); // If you want to choose hours to Days conversion

break;

}

}

public static void hoursToMinutes() { // called function

Scanner sc = new Scanner(System.in); // Scanner class declaration

int minutes; // variable declaration

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

int hours=sc.nextInt(); // Accept the number of hours

minutes = hours*60; // calculate minutes

System.out.println("There are "+minutes+" minutes in "+hours+" hours."); // print the number of minutes

}

public static void daysToHours() { // called function

Scanner sc = new Scanner(System.in); // Scanner class declaration

int hours; // variable declaration

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

int days=sc.nextInt(); // Accept number of days

hours = days*24; // calculate numebr of hours

System.out.println("There are "+hours+" hours in "+days+" days"); // print the number of hours

}

public static void minutesToHours() { // called function

Scanner sc = new Scanner(System.in); // Scanner class declaration

float hours; // variable declaration

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

int minutes=sc.nextInt(); // Accept the number of minutes

hours = (float)minutes/60; // calculate the number of hours

System.out.println("There are "+hours+" hours in "+minutes+" minutes"); // print the number of hours

}

public static void hoursToDays() { // called function

Scanner sc = new Scanner(System.in); // Scanner class declaration

float days; // variable declaration

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

int hours=sc.nextInt(); // Accept the number of hours

days = (float)hours/24; // calculate the number of days`

System.out.println("There are "+days+" days in "+hours+" hours"); // print the number of days

}

}

Output:


Related Solutions

JAVA FILE PROGRAM Write a contacts database program that presents the user with a menu that...
JAVA FILE PROGRAM Write a contacts database program that presents the user with a menu that allows the user to select between the following options: Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program...
in java Write a contacts database program that presents the user with a menu that allows...
in java Write a contacts database program that presents the user with a menu that allows the user to select between the following options: Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program prompts...
Write a method in JAVA to do the following: As the user to select from 2...
Write a method in JAVA to do the following: As the user to select from 2 different (default) pokemon or load their pokemon by giving you the name of their pokemon. Based on their selection (default or supplied name), read the move list and damage range from the input file(you do not need to create this) for the selected pokemon. Randomly select one of the default pokemon - Bulbasaur, Charmander, Squirtle (or you can add additional computer only options if...
java code Write a program that gives the user a menu of six choices (use integers)...
java code Write a program that gives the user a menu of six choices (use integers) to select from. The choices are circle, triangle, cone, cylinder, sphere, and quit. (The formulas are given below.) Once the figure is calculated, an informative message should be printed and the user shown the menu again, so that another choice can be made. The formulas are: Area of circle: a = 3.14 * radius * radius Area of triangle: a = ½ base *...
Your Java program should perform the following things:Take the input from the user about the...
Your Java program should perform the following things:Take the input from the user about the patient name, weight, birthdate, and height.Calculate Body Mass Index.Display person name and BMI Category.If the BMI Score is less than 18.5, then underweight.If the BMI Score is between 18.5-24.9, then Normal.If the BMI score is between 25 to 29.9, then Overweight.If the BMI score is greater than 29.9, then Obesity.Calculate Insurance Payment Category based on BMI Category.If underweight, then insurance payment category is low.If Normal...
Write a java program that perform the following: 1. Ask a user ti enter 10 student...
Write a java program that perform the following: 1. Ask a user ti enter 10 student test score on a test (100 point test and save the score in an array 2. Iterate through the array to find the average and highest of these score, print them out 3 Count how many student score below average and print them out 4 . Instructor decide to curve the student score using square root curving method( take the square root of the...
Write a program names EncryptDecrypt.java that has the following menu choices: Print menu and allow user...
Write a program names EncryptDecrypt.java that has the following menu choices: Print menu and allow user to choose options. The program must have a file dialogue box for text file. Output should be based on user choices. Read in a file Print the file to the console Encrypt the file and write it to the console Write out the encrypted file to a text file Clear the data in memory Read in an encrypted file Decrypt the file Write out...
Time Calculator – Intro To Programming - JAVA Write a program that asks the user to...
Time Calculator – Intro To Programming - JAVA Write a program that asks the user to enter a number of seconds. • There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. • There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or equal to...
Write a java program that will first display the following menu: Choose one of the following...
Write a java program that will first display the following menu: Choose one of the following 1- To add 2 double integers 2- To add 2 integer numbers 3- To add 3 double numbers 4- To add 3 integer numbers After reading user’s choice, use a switch case statement to call the corresponding method Void add 1 (double n1, double n2) Void add2() Double add3 (double n1, double n2, double n3) Double add4 ()
Write a program to prompt the user to display the following menu: Sort             Matrix                   Q
Write a program to prompt the user to display the following menu: Sort             Matrix                   Quit If the user selects ‘S’ or ‘s’, then prompt the user to ask how many numbers you wish to read. Then based on that fill out the elements of one dimensional array with integer numbers. Then sort the numbers and print the original and sorted numbers in ascending order side by side. How many numbers: 6 Original numbers:                     Sorted numbers 34                                                                         2          55                                                      ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT