Hi I need help creating a program in Java applications using knowledge learned f
ID: 3912635 • Letter: H
Question
Hi I need help creating a program in Java applications using knowledge learned from Chapter 6 of the Introduction of Java programming book.
Write a program that is based on a menu that will allow a user to enter a temp as either Kelvin, Celsius, or Fahrenheit. The user then will select from a menu as to what measurement they wish to convert to.
A menu that gives the user the a choice of entering a new value, processing/displaying the associated value, or exit
Selection (1) or (E)nter - The user is prompted for a temperature, lets say they type 100. and then K, C, or F for the scale
The user then is returned to the menu for their next choice
If they choose (2) or (P)rocess they should be asked which scale they wish to convert to), and number and scale stored should be converted and the new scale and displaye
The user then is returned to the menu for their next choice
Explanation / Answer
import java.util.*;
public class convert {
public static void main(String args[]) {
int more,choice,scale=0,convert_choice;
double value=0;
Scanner input=new Scanner(System.in);
do {
System.out.println("press 1:enter 2:process");
choice=input.nextInt();
switch(choice) {
case 1:{System.out.println("enter data");
value=input.nextFloat();
System.out.println("enter scale 1:K 2:F 3:C");
scale=input.nextInt();
break;
}
case 2:{
System.out.println("enter choice of conversion 1:K 2:F 3:C ");
convert_choice=input.nextInt();
if(scale==1) {
if(convert_choice==1)System.out.println(value+" Kelvin");
else if(convert_choice==2)System.out.println((1.8*(value-273)+32)+" F");
else if(convert_choice==3)System.out.println(value-273.15+" C");
}
else if(scale==2) {
if(convert_choice==1)System.out.println(((value-32)/1.8)+273+" Kelvin");
else if(convert_choice==2)System.out.println(value+" F");
else if(convert_choice==3)System.out.println(((value-32)/1.8)+" C");
}
else if(scale==3) {
if(convert_choice==1)System.out.println(value+273 +" Kelvin");
else if(convert_choice==2)System.out.println((value*1.8)+32 +" F");
else if(convert_choice==3)System.out.println(value +" C");
}
break;
}
}
System.out.println("press 1:more operation 2:exit");
more=input.nextInt();
}while(more==1);
}
}