Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Yvvy Chen
- AP CSA F Block
- Peg Leg
- September 10
- Temperature Converter
- */
- import java.util.Scanner;
- public class TempConverter {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner sc = new Scanner(System.in);
- //doubles for degree temperatures
- double F;
- double C;
- //beginning of loop for if they want to try another number
- String again = "yes";
- while (again.equals("yes") || again.equals("y")) {
- //menu because Peg Leg likes it
- System.out.println("Welcome to Temperature Converter\n");
- System.out.println("In which direction would you like to convert?");
- System.out.println("1) Fahrenheit to Celcius");
- System.out.println("2) Celcius to Fahrenheit\n");
- int direction = sc.nextInt();
- //F to C
- if (direction == 1) {
- System.out.println("What degree Fahrenheit would you like to convert?");
- F = sc.nextInt();
- C = (F-32) * 5/9.0;
- System.out.println("\n" + F + " degrees in Fahrenheit is equal to " + C + " degrees Celcius");
- }
- //C to F
- if (direction == 2) {
- System.out.println("What degree Celcius would you like to convert?");
- C = sc.nextInt();
- F = (9.0/5) * C + 32;
- System.out.println("\n" + C + " degrees in Celcius is equal to " + F + " degrees Fahrenheit");
- }
- //Ask if they want to try a different number
- System.out.println("\nWould you like to convert a different number? (Enter either \"yes\" or \"no\").");
- sc.nextLine();
- again = sc.nextLine();
- }
- //calling them a loser if no
- if (again.equals("no") || again.equals("n")) {
- System.out.println("Loser");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement