
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
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 + "](https://content.bartleby.com/qna-images/question/338e3266-4d38-4aac-b84a-ad112ae1b09a/5bb9edf8-7620-43dc-88d4-eff554b1f098/opzduy_thumbnail.png)
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 stepSolved 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.Similar questions
- Please answer question. This is pertaining to Java programming language 1-21arrow_forwardJava Program Write expressions that simulates rolling of two 6 sided dice three times and display results. (sample output below, random numbers generated from your program will be different ) Roll 1: 2 and 3 Roll 2: 3 and 6 Roll 3: 6 and 6arrow_forwardJava Programming: The program will figure out a number chosen by a user. Ask user to think of a number from 1 to 100. The program will make guesses and the user will tell the program to guess higher (h) or lower (l). Sample run of the program might look like below : Guess a number from 1 to 100. (here, the user is thinking of 81) Is it 50? (h/l/c): h Is it 75? (h/l/c): h Is it 88? (h/l/c): l Is it 81? (h/l/c): c Great! Do you want to play again? (y/n): y Guess a number from 1 to 100. (here the user is thinking 37) Is it 50? (h/l/c): l Is it 25? (h/l/c): h Is it 37? (h/l/c): c Great! Do you want to play again? (y/n): n our program should implement the binary search algorithm. Every time the program makes a guess it should guess the midpoint of the remaining possible values. Consider the first example above, in which the user has chosen the number 81: On the first guess, the possible values are 1 to 100. The midpoint is 50. The user responds by saying “higher” On the second…arrow_forward
- This needs to be done in Java! (Calculating Sales) An online retailer sells five products whose retail prices are as follows: Product 1, $2.98; product 2, $4.50; product 3, $9.98; product 4, $4.49 and product 5, $6.87. Write an application that reads a series of pairs of numbers as follows: product number quantity sold Your program should use a switch statement to determine the retail price for each product. It should calculate and display the total retail value of all products sold. Use a sentinel-controlled loop to determine when the program should stop looping and display the final results.arrow_forwardChapter 5. PC #2. Retail Price Calculator (page 312) Write a program that asks the user to enter an item’s wholesale cost and its markup percentage. It should then display the item’s retail price. For example: • If an item’s wholesale cost is 5.00 and its markup percentage is 100 percent, then the item’s retail price is 10.00. • If an item’s wholesale cost is 5.00 and its markup percentage is 50 percent, then the item’s retail price is 7.50. The program should have a method named calculateRetail that receives the wholesale cost and the markup percentage as arguments, and returns the retail price of the item. Class name: RetailPriceCalculator Here is a working code but please fix it so it will in Hypergrade which as all the test casses. I DO NOT NEED THANK YOU IN THE PROGRAM. IT HAS TO PASS ALL THE TEST CASSES PLEASE. THANK YOU!!!!!: import java.util.*;class RetailPriceCalculator{ // creating a method public static double calculateRetail(double wholesale,double…arrow_forward5. You are playing a game that has two dice - one die has 6 sides numbered 1 through 6 and the second die has 8 sides numbered 1 through 8. A turn involves rolling both die together. Write Java code to play 1,000 turns and keep track of the sum of the two dice in each roll I.e, (2 through 14). When all 1,000 turns have been completed, print a formatted table showing the value of the sum of the two dice (2 through 14) and the number of times that value occurred.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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