capncoolio

Temperature Converter

Apr 15th, 2010
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.71 KB | None | 0 0
  1. /*     
  2. **      Filename:   Temp.mash
  3. **      Author:     Thanasi Poulos
  4. **      Purpose:    Converting temperatures
  5. */
  6.  
  7. import console;
  8. int bigloop = 1;
  9. int selection = 0;
  10.  
  11.    while(selection == 0){
  12.       println("+------------------------+");
  13.       println("| TEMPERATURE CONVERTER! |");
  14.       println("|          -BY-          |");
  15.       println("|     THANASI POULOS     |");
  16.       println("|                        |");
  17.       println("| 1. C -> F              |");
  18.       println("| 2. F -> C              |");
  19.       println("| 3. C -> K              |");
  20.       println("| 4. K -> C              |");
  21.       println("| 5. F -> K              |");
  22.       println("| 6. K -> F              |");
  23.       println("| 7. EXIT                |");
  24.       println("+------------------------+");
  25.       print  ("Make a selection: ");
  26.       selection = readInt();
  27.  
  28.    while (selection == 1){
  29.       print("Enter degrees C to convert to degrees F: ");
  30.       double c=readDouble();
  31.       println();
  32.       double f=(c*9/5)+32;
  33.       println(c + " degrees celcius equals " + f + " degrees fahrenheit.");
  34.       println();
  35.       print("Type \"menu\" to return to the main menu or \"exit\" to close the program: ");
  36.       String response = readWord();
  37.       String compare = "menu";
  38.       boolean menu = equals(response, compare);
  39.       if (menu == true){
  40.            selection = 0;
  41.          }else{
  42.            selection = 7;
  43.          }
  44.       }
  45.    while (selection == 2){
  46.    print("Enter degrees F to convert to degrees C: ");
  47.       double f = readDouble();
  48.       println();
  49.       double c = (f-32)*(5.0/9.0);
  50.       println(f + " degrees farenheit equals " + c + " degrees celcius.");
  51.       println();
  52.       print("Type \"menu\" to return to the main menu or \"exit\" to close the program: ");
  53.       String response = readWord();
  54.       String compare = "menu";
  55.       boolean menu = equals(response, compare);
  56.       if (menu == true){
  57.            selection = 0;
  58.          }else if (menu == false){
  59.             selection = 7;
  60.          }
  61.       }
  62.     while (selection == 3){
  63.     print("Enter degrees C to convert to degrees K: ");
  64.       double c = readDouble();
  65.       println();
  66.       double k = c + 273.15;
  67.       println(c + " degrees celcius equals " + k + " degrees kelvin.");
  68.       println();
  69.       print("Type \"menu\" to return to the main menu or \"exit\" to close the program: ");
  70.       String response = readWord();
  71.       String compare = "menu";
  72.       String compare2 = "exit";
  73.       boolean menu = equals(response, compare);
  74.       if (menu == true){
  75.            selection = 0;
  76.          }else{
  77.             boolean exit = equals(response, compare2);
  78.             if (exit == true){
  79.                selection = 7;
  80.             }else{
  81.                println("Incorrect Parameter.");
  82.                selection = 7;
  83.             }
  84.          }
  85.       }
  86.    }
Add Comment
Please, Sign In to add comment