angeloeboy10

Untitled

Feb 16th, 2021 (edited)
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class Main{
  4.  
  5.     double temperature;
  6.     String celci, fahre;
  7.  
  8.     //constructor
  9.     public Main(){
  10.         temperature = 0.0;
  11.         fahre = "Your inputted Celcius is converted to Fahrenheit: ";
  12.         celci = "Your inputted Fahrenheit is converted to Celcius: ";
  13.  
  14.     }
  15.     //Method for getting fahrenheit
  16.     public double getCelcius(int fah){
  17.         temperature = (fah - 32) / 1.8;
  18.         return temperature;
  19.     }
  20.  
  21.  
  22.     //Method for getting celcius
  23.     public double getFahrenheit (int cel){
  24.         temperature = (1.8 * cel) + 32;
  25.         return temperature;
  26.     }
  27.  
  28.  
  29.     //Main method
  30.     public static void main(String[] args) {
  31.         //Creation of object
  32.         Main test = new Main();
  33.  
  34.         Scanner scan = new Scanner(System.in);
  35.  
  36.         System.out.println("What do u want to do? \n A. Fahrenheit to Celcius \n B. Celcius to Fahrenheit ");
  37.  
  38.         String choice = scan.nextLine();
  39.         System.out.println("Type it:");
  40.  
  41.         int number = scan.nextInt();
  42.  
  43.         if(choice.equalsIgnoreCase("a")){
  44.  
  45.             System.out.println(test.celci + test.getCelcius(number));
  46.         }else if(choice.equalsIgnoreCase("b")){
  47.             System.out.println(test.fahre +  test.getFahrenheit(number));
  48.  
  49.         }
  50.  
  51.     }
  52. }
Add Comment
Please, Sign In to add comment