Created
September 14, 2018 02:54
-
-
Save landjd19/e1c95e04e149d0b0af1f1a49604fc063 to your computer and use it in GitHub Desktop.
Temperature Converter Java Project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Allows user to convert temperatures from fahrenheit to celsius and vice versa. | |
* | |
* Jake Landaiche (your name) | |
* | |
* 9/13/18 (a version number or a date) | |
* | |
*/ | |
import java.util.*; | |
public class TempConverter { | |
public static void main(String[] args) { | |
double input; | |
double output; | |
boolean inUse = true; | |
boolean newTemp = true; | |
Scanner sc = new Scanner(System.in); | |
while(inUse == true){ | |
System.out.println("This is the temperature converter"); | |
System.out.println("Please enter your temperature."); | |
while(newTemp == true){ | |
input = sc.nextInt(); | |
System.out.println("You Input " + input + " Degrees"); | |
System.out.println("If you are converting from Fahrenheit to Celsius, press 1. If you are converting from Celsius to Fahrenheit, press 2."); | |
int whichUnit = sc.nextInt(); | |
if(whichUnit == 1){ | |
output = (input - 32) * 5/9.0; | |
output = ((int)(output * 100)) / 100.0; | |
System.out.println("Your New Temperature is " + output + " Degrees"); | |
newTemp = false; | |
} else { | |
output = ((9.0/5) * input) - 32; | |
output = ((int)(output * 100)) / 100.0; | |
System.out.println("Your New Temperature is " + output + " Degrees"); | |
newTemp = false; | |
} | |
} | |
if(newTemp == false){ | |
System.out.println("Would You Like to Convert Again? Press 1 to Continue, or Press 2 to Exit."); | |
int continueAnswer = sc.nextInt(); | |
if(continueAnswer == 1){ | |
newTemp = true; | |
inUse = true; | |
} else { | |
newTemp = false; | |
inUse = false; | |
System.out.println("Goodbye!"); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment