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.
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
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 + "](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F338e3266-4d38-4aac-b84a-ad112ae1b09a%2F5bb9edf8-7620-43dc-88d4-eff554b1f098%2Fopzduy_processed.png&w=3840&q=75)
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
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 7 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
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.Recommended textbooks for you
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781305480537/9781305480537_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781305480537/9781305480537_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT