Rabu, 01 Mei 2013

Menentukan pengeluaran Bahan Bakar menggunakan Java


Sekarang kita membuat Project dengan nama Mobil lalu buat class BahanBakar

package mobil;

/**
 *
 * @author riezka
 */
public class BahanBakar {
 
    public float A, B, C, D, E, F;
    public float AkeB = 45;
    public float BkeC = 51;
    public float CkeD = 38;
    public float DkeE = 104;
    public float EkeF = 93;
    public float Kota;
 
    public float liter()
        {
        Kota = (float)(9);
        return Kota;
        }
    public float JarakAB()
        {
        Kota = (this.AkeB);
        return Kota;
        }
    public float JarakAC()
        {
        Kota = (this.AkeB + this.BkeC);
        return Kota;
        }
    public float JarakAD()
        {
        Kota = (this.AkeB + this.BkeC + this.CkeD);
        return Kota;
        }
    public float JarakAE()
        {
        Kota = (this.AkeB + this.BkeC + this.CkeD + this.DkeE);
        return Kota;
        }
    public float JarakAF()
        {
        Kota = (this.AkeB + this.BkeC + this.CkeD + this.DkeE + this.EkeF);
        return Kota;
        }
 
    public float JarakBC()
        {
        Kota = (this.BkeC);
        return Kota;
        }
    public float JarakBD()
        {
        Kota = (this.BkeC + this.CkeD);
        return Kota;
        }
    public float JarakBE()
        {
        Kota = (this.BkeC + this.CkeD + this.DkeE);
        return Kota;
        }
    public float JarakBF()
        {
        Kota = (this.BkeC + this.CkeD + this.DkeE + this.EkeF);
        return Kota;
        }
 
    public float JarakCD()
        {
        Kota = (this.CkeD);
        return Kota;
        }
    public float JarakCE()
        {
        Kota = (this.CkeD + this.DkeE);
        return Kota;
        }
    public float JarakCF()
        {
        Kota = (this.CkeD + this.DkeE + this.EkeF);
        return Kota;
        }
 
    public float JarakDE()
        {
        Kota = (this.DkeE);
        return Kota;
        }
    public float JarakDF()
        {
        Kota = (this.DkeE + this.EkeF);
        return Kota;
        }
 
    public float JarakEF()
        {
        Kota = (this.EkeF);
        return Kota;
        }
}

Lalu di class Mobil


public class Mobil {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
     
        BahanBakar M = new BahanBakar();
     
        System.out.println("=========================================================");
     
        System.out.format("Jarak Kota A ke F\t= %10.1f km \n", M.JarakAF());
        System.out.format("Bahan Bakar Kota A ke F\t= %10.1f liter \n", M.JarakAF()/ M.liter());
     
        System.out.println("=========================================================");
     
        System.out.format("Jarak Kota B ke E\t= %10.1f km \n", M.JarakBE());
        System.out.format("Bahan Bakar Kota B ke E\t= %10.1f liter \n", M.JarakBE()/ M.liter());
     
        System.out.println("==========================================================");
     
        System.out.format("Jarak Kota A ke F lalu ke Kota B\t= %10.1f km \n", M.JarakAF()+ M.JarakBF());
        System.out.format("Bahan Bakar Kota A ke F lalu ke Kota B\t= %10.1f liter \n", M.JarakAF()+ M.JarakBF()/ M.liter());
     
        System.out.println("=========================================================");
     
        System.out.format("Jarak Kota A-F-E-D-C-D-E-D-E-F\t\t= %10.1f km \n", M.JarakAF()+ (M.JarakEF()*2)+ (M.JarakDE()*4)+ (M.JarakCD()*2));
        System.out.format("Bahan Bakar Kota A-F-E-D-C-D-E-D-E-F\t= %10.1f liter \n", M.JarakAF()+ (M.JarakEF()*2)+ (M.JarakDE()*4)+ (M.JarakCD()*2)/ M.liter());
     
        System.out.println("=========================================================");
    }
}



Membuat Project Gaji menggunakan Java

Pertama kita membuat Project yang berjudul ProjectGaji


public class ProjectGaji {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        {
        Gaji G = new Gaji();
     
        G.KodeKaryawan = "K005";
        G.NamaKaryawan = "Riezka Layli Khusnia";
        G.StatusMenikah = 'n';
        G.JmlAnak = 0;
     
        G.Golongan = "IIID";
        G.TotPinjaman = 100000;
        G.AngsRumah = 1000000;

//lalu membuat keluaran outputnya

        System.out.println("======================================");
        System.out.println("Kode Karyawan\t: "+G.KodeKaryawan);
        System.out.println("Nama Karyawan\t: "+G.NamaKaryawan);
        System.out.println("Status Menikah\t: "+G.StatusMenikah);
        
        System.out.println("======================================");

        G.HitungGajiPokok();
        
        System.out.println("======================================");
        System.out.format("Tunjangan Istri\t: Rp %10.1f \n", G.HitungTunjIstri(G.StatusMenikah));
        System.out.format("Tunjangan Anak\t: Rp %10.1f \n", G.HitungTunjAnak(G.JmlAnak));
        System.out.format("Potongan\t: Rp %10.1f \n", G.HitungPotongan());
        
        System.out.println("======================================");

        System.out.format("Gaji Bersih\t: Rp %10.1f \n", G.HitungGajiBersih());
        
        System.out.println("======================================");
        
        G.SimulasiAngsuranPinjaman();
        
        System.out.println("======================================");
        
        G.SimulasiAngsuranRumah();
        
        System.out.println("======================================");
        }

setelah itu kita membuat class untuk menulis rumus-rumusnya

package projectgaji;

/**
 *
 * @author riezka
 */
public class Gaji {

//menuliskan object yang diketahui
    public String KodeKaryawan;
    public String NamaKaryawan;
    public String Golongan;
    public float TotPinjaman;
    public float AngsRumah;
    public float GajiPokok;
    public char StatusMenikah;
    public int JmlAnak;


    public void HitungGajiPokok()
        {
        switch (this.Golongan) 
            {
            case "IIIA":
                GajiPokok = (float)(1500000);
                break;
            case "IIIB":
                GajiPokok = (float)(1850000);
                break;
            case "IIIC":
                GajiPokok = (float)(2100000);
                break;
            case "IIID":
                GajiPokok = (float)(2350000);
                break;
            }
        System.out.format("Gaji Pokok\t: Rp %10.1f \n", this.GajiPokok);
        }
    public float HitungTunjIstri(char s)
        {
        float TunjIstri = 0;
        if (s == 'y')
            {
            TunjIstri = (float)(0.1*this.GajiPokok);
            }
        return TunjIstri;
        }
    public float HitungTunjAnak(int n)
        {
        float TunjAnak;
        TunjAnak = (float)(n*0.05*this.GajiPokok);
        return TunjAnak;
        }
    public float HitungPotongan()
        {
        float JmlPotongan;
        JmlPotongan = (float)(0.01*(this.GajiPokok + this.HitungTunjIstri(StatusMenikah) + this.HitungTunjAnak(JmlAnak)));
        return JmlPotongan;
        }
    public float HitungGajiBersih()
        {
        float GajiBersih;
        GajiBersih = (float)(this.GajiPokok + this.HitungTunjIstri(StatusMenikah) + this.HitungTunjAnak(JmlAnak) - this.HitungPotongan());
        return GajiBersih;
        }
    public void SimulasiAngsuranPinjaman()
        {
        float Angsuran = 0, TotalAngsuran = 0;
        int Bulan;
        switch (this.Golongan) 
            {
            case "IIIA":
                Angsuran = (float)(50000);
                break;
            case "IIIB":
                Angsuran = (float)(100000);
                break;
            case "IIIC":
                Angsuran = (float)(150000);
                break;
            case "IIID":
                Angsuran = (float)(200000);
                break;
            }
        System.out.format("Total Pinjaman\t: Rp %10.1f \n", this.TotPinjaman);
        
        Bulan = 0;
        while (TotalAngsuran < this.TotPinjaman)
            {
            TotalAngsuran += Angsuran;
            Bulan++;
            System.out.format("Angsuran Bulan ke-%2d : Rp %10.1f \n", Bulan,TotalAngsuran);
            }
        }
    public void SimulasiAngsuranRumah()
        {
        float AngsuranRumah = 0, TotalAngsRumah = 0;
        int Bulan;
        switch (this.Golongan) 
            {
            case "IIIA":
                AngsuranRumah = (float)(0.05*(this.GajiPokok));
                break;
            case "IIIB":
                AngsuranRumah = (float)(0.07*(this.GajiPokok));
                break;
            case "IIIC":
                AngsuranRumah = (float)(0.10*(this.GajiPokok));
                break;
            case "IIID":
                AngsuranRumah = (float)(0.15*(this.GajiPokok));
                break;
            }
        System.out.format("Angsuran Rumah\t: Rp %10.1f \n", this.AngsRumah);
        
        Bulan = 0;
        while (TotalAngsRumah < this.AngsRumah)
            {
            TotalAngsRumah += AngsuranRumah;
            Bulan++;
            System.out.format("Angsuran Bulan ke-%2d : Rp %10.1f \n", Bulan, TotalAngsRumah);
            }
        }
}