Solutions for Class 10 ICSE Logix Kips Computer Applications with BlueJ Java | IT Developer <?php echo $page_title; ?>
IT Developer

Conditional Constructs in Java

Chapter 8

Conditional Constructs in Java

Class 10 - Logix Kips ICSE Computer Applications with BlueJ


Share with a Friend

Java Program: Time Conversion Table Using Menu


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

import java.util.Scanner;

 

public class TimeConversion {

    public static void main(String[] args) {

 

        // Title

        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");

 

        Scanner sc = new Scanner(System.in);

 

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

        int choice = sc.nextInt();

 

        double value, result;

 

        switch (choice) {

            case 1:

                System.out.print("Enter milliseconds: ");

                value = sc.nextDouble();

                result = value / 1000;

                System.out.println("Seconds = " + result);

                break;

 

            case 2:

                System.out.print("Enter milliseconds: ");

                value = sc.nextDouble();

                result = value / (1000 * 60);

                System.out.println("Minutes = " + result);

                break;

 

            case 3:

                System.out.print("Enter seconds: ");

                value = sc.nextDouble();

                result = value * 1000;

                System.out.println("Milliseconds = " + result);

                break;

 

            case 4:

                System.out.print("Enter seconds: ");

                value = sc.nextDouble();

                result = value / 60;

                System.out.println("Minutes = " + result);

                break;

 

            case 5:

                System.out.print("Enter minutes: ");

                value = sc.nextDouble();

                result = value * 60 * 1000;

                System.out.println("Milliseconds = " + result);

                break;

 

            case 6:

                System.out.print("Enter minutes: ");

                value = sc.nextDouble();

                result = value * 60;

                System.out.println("Seconds = " + result);

                break;

 

            default:

                System.out.println("Invalid choice! Please select between 1 and 6.");

        }

 

        sc.close();

    }

}

Output

Sample Output 

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
Enter your choice: 1
Enter milliseconds: 5000
Seconds = 5.0

📝 Explanation

  • Menu is displayed using print statements
  • User selects conversion type
  • switch-case performs the selected conversion
  • Correct formula is applied based on the choice
  • An error message is shown for an invalid choice