Sekarang mari kita belajar untuk mencoba menghitung gaji karyawan
Contoh soalnya



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package soal4;
/**
*
* @author yohanes
*/
public class operasi {
public float J1,J2,J3,J4,J5,hasilakhir,jarak,AB,BC,CD,DE,EF;
public float J1()
{
this.jarak =AB/9;
return jarak;
}
public float J2()
{
this.jarak =BC/9;
return jarak;
}
public float J3()
{
this.jarak =CD/9;
return jarak;
}
public float J4()
{
this.jarak =DE/9;
return jarak;
}
public float J5()
{
this.jarak =EF/9;
return jarak;
}
public void jumlah1()
{
this.hasilakhir= (float)(J1()+J2()+J3()+J4()+J5());
System.out.println("Maka banyaknya bensin yang diperlukan untuk AF: "+ Math.ceil(this.hasilakhir));
}
public void jumlah2()
{
this.hasilakhir= (float)(J3()+J4());
System.out.println("Maka banyaknya bensin yang diperlukan untuk BF: "+ this.hasilakhir);
}
public void jumlah3()
{
this.hasilakhir= (float)(J1()+J2()+J3()+J4()+J5()+J3()+J4() );
System.out.println("Maka banyaknya bensin yang diperlukan untuk A ke F, kemudian kembali lagi ke kota B: "+ this.hasilakhir);
}
public void jumlah4()
{
this.hasilakhir= (float)(J1()+J2()+J3()+J4()+J5()+J4()+J3()+J4()+J5() );
System.out.println("Maka banyaknya bensin yang diperlukan untuk dari kota A ke F – E – D – C – D – E – D – E – F: "+ this.hasilakhir);
}
}
class masukan
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package soal4;
/**
*
* @author yohanes
*/
public class masukan {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
operasi op1=new operasi();
op1.AB=45;
op1.BC=51;
op1.CD=38;
op1.DE=104;
op1.EF=93;
op1.jumlah1();
op1.jumlah2();
op1.jumlah3();
op1.jumlah4();
}
}

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pohon;
/**
*
* @author yohanes
*/
public class Pohon {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
operasi op1=new operasi();
op1.orang_pohon=20;
op1. tinggi_orang=180;
op1.sudut=30;
op1.tp();
}
}
2. Class Operasi
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pohon;
/**
*
* @author yohanes
*/
public class operasi {
public float orang_pohon;
public float tinggi_orang;
public float hasil,hasilakhir;
public float sudut;
public float to()
{
this.hasil=this.tinggi_orang/100;
return hasil;
}
public float s()
{
this.hasil= (float)((this.sudut/180)*3.14);
return hasil;
}
public float sudut_jadi()
{
this.hasil= (float) Math.tan(s());
return hasil;
}
public float y()
{
this.hasil= this.orang_pohon* sudut_jadi();
return hasil;
}
public void tp()
{
this.hasilakhir= to()+ y();
System.out.println("Maka tinggi pohon adalah :"+hasilakhir);
}
}

/*
* 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

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package contoh2;
/**
*
* @author yohanes
*/
public class Contoh2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.println("Hello World");
}
}

Sebuah arsitek memperkirakan biaya yang diperlukan untuk membangun sebuah rumah. Berikut ini merupakan bahan material utama yang dibutuhkan untuk membangun rumah tersebut: -Pasir : 500 m^3 (harga Rp 120000/m^3) -Semen : 70 sak (Harga Rp 90000/sak) -Batu bata : 10000 buah (harga Rp 500/buah) -Kayu Kalimantan : 300 m^2 (Harga Rp. 300000/buah) -Batu kali untuk pondasi : 200 buah (Harga Rp 1000/buah) -Genting : 500 buah (harga Rp 2000/buah) Nah, buatlah sebuah program java untuk menghhitung berapa biaya yang diperlukan untuk membangun rumah tersebut, dengan terlebih dahulu merancang class-classnya , serta atribut dan methodnya ya :)1. ini adalah isi untuk class oprasi
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package arsitek;
/**
*
* @author yohanes
*/
public class material {
public int tampilhasil,hasilakhir,muncul;
public int semen;
public int pasir;
public int batubata;
public int kaykalimantan;
public int batukalipondasi;
public int genting;
public int hasil;
//method
//karena non void maka harus ada returnnya
public int pesansemen()
{
this.hasil= (this.semen *(int)90000);
return hasil;
}
public int pesanpasir()
{
this.hasil= (this.pasir *(int)120000);
return hasil;
}
public int pesanbatubata()
{
this.hasil= (this.batubata *(int)500);
return hasil;
}
public int pesankaykalimantan()
{
this.hasil= (this.kaykalimantan *(int)200000);
return hasil;
}
public int pesanbatukalipondasi()
{
this.hasil= (this.batukalipondasi *(int)1000);
return hasil;
}
public int pesangenting()
{
this.hasil= (this.genting *(int)2000);
return hasil;
}
public void tambah()
{
this.hasilakhir= (int)(pesanbatubata() + pesanbatukalipondasi() + pesangenting() + pesankaykalimantan() + pesanpasir() + pesansemen());
System.out.println("Maka harga total yang harus dibayar adalah: Rp" +this.hasilakhir);
}
}
2. Dan ini adalah isi untuk class Material
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package arsitek;
/**
*
* @author yohanes
*/
public class operasi {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// atribut
material op1=new material();
op1.semen= (int)70;
op1.batubata= (int)10000;
op1.batukalipondasi= (int)200;
op1.genting= (int)500;
op1.kaykalimantan= (int)300;
op1.pasir= (int)500;
op1.pesanbatubata();
op1.pesanbatukalipondasi();
op1.pesangenting();
op1.pesankaykalimantan();
op1.pesanpasir();
op1.pesansemen();
//tampilkan output
op1.tambah();
}
}