Advertisement
wreed12345

Untitled

Oct 3rd, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Converter {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner keyboard = new Scanner(System.in);
  7.  
  8.         System.out.println("Welcome to the Fahrenheit/Celsius Converter!");
  9.         System.out
  10.                 .println("To convert, type in your temperature and the identify if you are using fahrenheit or celsius.");
  11.         System.out.println("Example: 69F or 69C F = Fahrenheit C = Celsius");
  12.  
  13.         String temperature;
  14.         char f = 'f';
  15.         char c = 'c';
  16.         char C = 'C';
  17.         double answer, temp;
  18.  
  19.         temperature = keyboard.nextLine();
  20.  
  21.         if (temperature.contains("C")) {
  22.             temperature = temperature.replace(C, ' ');
  23.             temp = Double.valueOf(temperature);
  24.             answer = (double) (temp * (9 / 5) + 32);
  25.             System.out.println("Poof! The temperature is " + answer + "F");
  26.         } else if (temperature.contains("c")) {
  27.                 temperature = temperature.replace(c, ' ');
  28.                 temp = Double.valueOf(temperature);
  29.                 answer = (double) (temp * (9 / 5) + 32);
  30.                 System.out.println("Poof! The temperature is " + answer + "F");
  31.         } else if (temperature.contains("F")) {
  32.                 temperature = temperature.replace(f, ' ');
  33.                 temp = Double.valueOf(temperature);
  34.                 answer = (double) ((temp - 30) * (5 / 9));
  35.                 System.out.println("Poof! The temperature is " + answer
  36.                             + "C");
  37.         } else if (temperature.contains("f")) {
  38.                 temperature = temperature.replace(f, ' ');
  39.                 temp = Double.valueOf(temperature);
  40.                 answer = (double) ((temp - 30) * (5/9));
  41.                 System.out.println("Poof! The temperature is " + answer
  42.                                 + "C");
  43.         } else {
  44.             System.out.println("You entered the temperature wrong!");
  45.         }
  46.         keyboard.close();
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement