Problem 2: Write a Java program to perform the following: Present the user with a menu of selections to convert among different units of measure as follows: 1, centimeters to inches 2. kilograms to pounds 3. miles to kilometers 4. grams to ounces 5. meters to feet 9. EXIT Use a switch statement to implement the above.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 28PE
icon
Related questions
Question
### Problem 2:
**Task:**
Write a Java program to perform the following:

Present the user with a menu of selections to convert among different units of measure as follows:

1. Centimeters to inches
2. Kilograms to pounds
3. Miles to kilometers
4. Grams to ounces
5. Meters to feet
9. EXIT

**Instructions:**
- Use a switch statement to implement the above options.

### Explanation for Educational Website:

In this assignment, students are required to design a Java program capable of performing various unit conversions. The user is presented with a menu that allows them to choose which conversion they would like to perform. Here’s a detailed breakdown of what your program should do:

1. **Centimeters to Inches**
   - Convert a length in centimeters to inches.
  
2. **Kilograms to Pounds**
   - Convert a mass in kilograms to pounds.

3. **Miles to Kilometers**
   - Convert a distance in miles to kilometers.

4. **Grams to Ounces**
   - Convert a weight in grams to ounces.

5. **Meters to Feet**
   - Convert a length in meters to feet.

9. **EXIT**
   - Exit the program.

**Implementation Note:**
The program should use a switch statement to handle the user's menu selection and perform the appropriate conversion based on the user's choice.

**Example Code:**
Here is a simple example to get you started:

```java
import java.util.Scanner;

public class UnitConverter {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int choice;
        
        do {
            System.out.println("Select conversion type:");
            System.out.println("1. Centimeters to inches");
            System.out.println("2. Kilograms to pounds");
            System.out.println("3. Miles to kilometers");
            System.out.println("4. Grams to ounces");
            System.out.println("5. Meters to feet");
            System.out.println("9. EXIT");
            choice = scanner.nextInt();
            
            switch (choice) {
                case 1:
                    System.out.print("Enter centimeters: ");
                    double cm = scanner.nextDouble();
                    System.out.println(cm + " cm equals " + cm / 2.54 + " inches.");
                    break;
                case 2:
                    System.out.print("Enter kilograms: ");
                    double kg = scanner.nextDouble();
                    System.out.println(kg + "
Transcribed Image Text:### Problem 2: **Task:** Write a Java program to perform the following: Present the user with a menu of selections to convert among different units of measure as follows: 1. Centimeters to inches 2. Kilograms to pounds 3. Miles to kilometers 4. Grams to ounces 5. Meters to feet 9. EXIT **Instructions:** - Use a switch statement to implement the above options. ### Explanation for Educational Website: In this assignment, students are required to design a Java program capable of performing various unit conversions. The user is presented with a menu that allows them to choose which conversion they would like to perform. Here’s a detailed breakdown of what your program should do: 1. **Centimeters to Inches** - Convert a length in centimeters to inches. 2. **Kilograms to Pounds** - Convert a mass in kilograms to pounds. 3. **Miles to Kilometers** - Convert a distance in miles to kilometers. 4. **Grams to Ounces** - Convert a weight in grams to ounces. 5. **Meters to Feet** - Convert a length in meters to feet. 9. **EXIT** - Exit the program. **Implementation Note:** The program should use a switch statement to handle the user's menu selection and perform the appropriate conversion based on the user's choice. **Example Code:** Here is a simple example to get you started: ```java import java.util.Scanner; public class UnitConverter { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int choice; do { System.out.println("Select conversion type:"); System.out.println("1. Centimeters to inches"); System.out.println("2. Kilograms to pounds"); System.out.println("3. Miles to kilometers"); System.out.println("4. Grams to ounces"); System.out.println("5. Meters to feet"); System.out.println("9. EXIT"); choice = scanner.nextInt(); switch (choice) { case 1: System.out.print("Enter centimeters: "); double cm = scanner.nextDouble(); System.out.println(cm + " cm equals " + cm / 2.54 + " inches."); break; case 2: System.out.print("Enter kilograms: "); double kg = scanner.nextDouble(); System.out.println(kg + "
Expert Solution
steps

Step by step

Solved in 4 steps with 7 images

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT