Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Main{
- double temperature;
- String celci, fahre;
- //constructor
- public Main(){
- temperature = 0.0;
- fahre = "Your inputted Celcius is converted to Fahrenheit: ";
- celci = "Your inputted Fahrenheit is converted to Celcius: ";
- }
- //Method for getting fahrenheit
- public double getCelcius(int fah){
- temperature = (fah - 32) / 1.8;
- return temperature;
- }
- //Method for getting celcius
- public double getFahrenheit (int cel){
- temperature = (1.8 * cel) + 32;
- return temperature;
- }
- //Main method
- public static void main(String[] args) {
- //Creation of object
- Main test = new Main();
- Scanner scan = new Scanner(System.in);
- System.out.println("What do u want to do? \n A. Fahrenheit to Celcius \n B. Celcius to Fahrenheit ");
- String choice = scan.nextLine();
- System.out.println("Type it:");
- int number = scan.nextInt();
- if(choice.equalsIgnoreCase("a")){
- System.out.println(test.celci + test.getCelcius(number));
- }else if(choice.equalsIgnoreCase("b")){
- System.out.println(test.fahre + test.getFahrenheit(number));
- }
- }
- }
Add Comment
Please, Sign In to add comment