menghitung Konversi suhu dengan java

Nah teman-teman, saat ini saya sedang me-review bagaimana caranya kita mengkonversikan suhu dari derajat ke suhu-suhu yang lain dengan menggunakan pemrograman java. Nah saya pun juga tahu dari teman dan dosen saya , ok mari kita belajar!! 1.
Class "Konversi suhu"
Sebenarnya untuk penamaan class, terserah sesuka hati teman2 semua, yang penting adalah didalam prosesnya namanya harus sesuai dengan nama class yang agan2 semua tulis ok
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package suhu;

/**
 *
 * @author yohanes
 */
public class konversisuhu {
    //deklarasi atribut atau properties
    public float celcius;
    public float hasilr;
    public float hasilk;
    public float hasilf;
    
    public void ctor()
    {
        this.hasilr = (float) (this.celcius*0.8);
    }
    public void ctok()
    {
      this.hasilk= (float) (this.celcius+273);  
    }
    public void ctof()
    {
      this.hasilf=(float) ((this.celcius*1.8)+32);  
    }
    //method tampil hasil
    public void tampilhasil()
    {
        System.out.println("tampilhasil dari celcius ke reamur :" + this.hasilr);
        System.out.println("tampilhasil dari celcius ke kelvin:" + this.hasilk);
        System.out.println("tampilhasil dari celcius ke farenheit:" + this.hasilf);
    }  
}

nah yang kedua adalah class cara hitung
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package suhu;

/**
 *
 * @author yohanes
 */
public class carahitung {
    public static void main(String[] args) {
    
        //instantisasi obyek 'op1'
        konversisuhu op1= new konversisuhu();
        op1.celcius=100;
        op1.ctor();
       
        op1.ctok();
       
        op1.ctof();
    
        op1.tampilhasil();
    }
    
    }
 
ok

1 comments:

Wah panjang juga ya mas. Tapi ga papa, tetep bisa dimengerti kok walau aku juga baru belajar Java. Izin praktik ya mas.
Jadi terinpirasi untuk menulis tentang Java juga nih. Hehe... Thanks mas.


EmoticonEmoticon