Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

package com.

konversisuhu;

import java.util.Scanner;
public class konversisuhu {

static double suhu;


static char awal;

public static void main(String[] args) {


celcius fromcelcius = new celcius();
fahrenheit fromfahrenheit = new fahrenheit();
reamur fromreamur = new reamur();
kelvin fromkelvin = new kelvin();

double Fahrenheit, Kelvin, Celcius, Reamur;


boolean valid = false;
Scanner input = new Scanner(System.in);

while(valid!=true)
{
System.out.println("Konversi Suhu");
System.out.print("Masukkan Suhu [C/F/R/K] (misal: 100 R)= ");
suhu = input.nextDouble();
awal = input.next().charAt(0);

switch(awal){
case 'C':
Reamur = fromcelcius.toreamur();
Fahrenheit = fromcelcius.tofahrenheit();
Kelvin = fromcelcius.tokelvin();
System.out.println("Suhu = "+suhu+" Celcius");
System.out.println("Fahrenheit = "+Fahrenheit);
System.out.println("Kelvin = "+Kelvin);
System.out.println("Reamur = "+Reamur);
valid=true;
break;
case 'F':
Celcius = fromfahrenheit.tocelcius();
Reamur = fromfahrenheit.toreamur();
Kelvin = fromfahrenheit.tokelvin();
System.out.println("Suhu ="+suhu+" Fahrenheit");
System.out.println("Celcius = "+Celcius);
System.out.println("Kelvin = "+Kelvin);
System.out.println("Reamur = "+Reamur);
valid=true;
break;
case 'K':
Celcius = fromkelvin.tocelcius();
Reamur = fromkelvin.toreamur();
Fahrenheit = fromkelvin.tofahrenheit();
System.out.println("Suhu ="+suhu+" Kelvin");
System.out.println("Celcius = "+Celcius);
System.out.println("Fahrenheit = "+Fahrenheit);
System.out.println("Reamur = "+Reamur);
valid=true;
break;
case 'R':
Celcius = fromreamur.tocelcius();
Fahrenheit = fromreamur.tofahrenheit();
Kelvin = fromreamur.tokelvin();
System.out.println("Suhu ="+suhu+" Reamur");
System.out.println("Celcius = "+Celcius);
System.out.println("Fahrenheit = "+Fahrenheit);
System.out.println("Kelvin = "+Kelvin);
valid=true;
break;
default :
System.out.println("Masukkan Suhu Dengan Benar [C,F,K,R]");
}
}
}
}

package com.konversisuhu;

public class kelvin {


double tofahrenheit(){
return (konversisuhu.suhu*1.8-459.67);
}
double toreamur(){
return ((konversisuhu.suhu-273.15)*0.8);
}
double tocelcius(){
return (konversisuhu.suhu-273.15);
}
}

You might also like