Computer Applications

Write a menu driven program to display the following menu:

Conversion Table
============

  1. Milliseconds to Seconds
  2. Milliseconds to Minutes
  3. Seconds to Milliseconds
  4. Seconds to Minutes
  5. Minutes to Milliseconds
  6. Minutes to Seconds

For an incorrect choice, display an appropriate error message.

Hint: 1 second = 1000 milliseconds

Java

Java Conditional Stmts

18 Likes

Answer

import java.util.Scanner;

public class KboatTimeConversion
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("Conversion Table");
        System.out.println("================");
        System.out.println("1. Milliseconds to Seconds");
        System.out.println("2. Milliseconds to Minutes");
        System.out.println("3. Seconds to Milliseconds");
        System.out.println("4. Seconds to Minutes");
        System.out.println("5. Minutes to Milliseconds");
        System.out.println("6. Minutes to Seconds");
        System.out.print("Enter your choice: ");
        int choice = in.nextInt();
        double ip = 0, op = 0;
        switch (choice) {
            case 1:
            System.out.print("Enter Milliseconds: ");
            ip = in.nextDouble();
            op = ip / 1000;
            System.out.println("Seconds = " + op);
            break;
            
            case 2:
            System.out.print("Enter Milliseconds: ");
            ip = in.nextDouble();
            op = ip / 1000 / 60;
            System.out.println("Minutes = " + op);
            break;
            
            case 3:
            System.out.print("Enter Seconds: ");
            ip = in.nextDouble();
            op = ip * 1000;
            System.out.println("Milliseconds = " + op);
            break;
            
            case 4:
            System.out.print("Enter Seconds: ");
            ip = in.nextDouble();
            op = ip / 60;
            System.out.println("Minutes = " + op);
            break;
            
            case 5:
            System.out.print("Enter Minutes: ");
            ip = in.nextDouble();
            op = ip * 60 * 1000;
            System.out.println("Milliseconds = " + op);
            break;
            
            case 6:
            System.out.print("Enter Minutes: ");
            ip = in.nextDouble();
            op = ip * 60;
            System.out.println("Seconds = " + op);
            break;
            
            default:
            System.out.println("Incorrect choice");
        }
    }
}

Output

Answered By

7 Likes


Related Questions