/**
* Write a description of class guessingGame here.
*
* @author (Peter)
* @version (9/7/2017)
*/
import java.util.*;
public class TempConverter
{
public static void main(String args[]){
{
boolean why = true;
double temp;//variable used later
Scanner scan = new Scanner(System.in);
while(why==true){//restarts the program if user so choose
System.out.println("Enter 1 for conversion to fahrenheit,2 for conversion to celsius.");
int num = scan.nextInt();//takes input from user and set the variable num to it
if(num==1){
//this section converts the temperature to fahrenheit
System.out.println("Please enter a temperature that's in celsius :)");
temp = scan.nextInt();//takes input from user and set the variable temp to it
System.out.println("Converting your number into Fahrenheit...");
temp = ((temp*(1.8))+32);//temperature converted here
System.out.println(temp + "fahrenheit.");
}
else{
if(num==2){
//this section converts the temperature to celsius
System.out.println("Please enter a temperature that's in fahrenheit :)");
temp = scan.nextInt();//takes input from user and set the variable temp to it
System.out.println("Converting your number into Fahrenheit...");
temp = ((temp-32)*(.55));//temperature converted right here
System.out.println(temp + "celsius.");
}
else{
//the system gets grumpy if you fail to chose the options correctlyq
System.out.println("Please restart program and enter in 1 or 2.");
}
}
System.out.println("do you want to convert another temperature? type 1 to play again and 2 to quit");
num = scan.nextInt();
if(num==2){
why = false;
}
}
}
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.