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.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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

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

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

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education