63 Contoh Program Java Pada Netbeans

63 Contoh Program Java Pada Netbeans

63 Contoh Program Java Pada Netbeans


1. PROGRAM 1
package pertemuan1_1;
public class PERTEMUAN1_1 {
    public static void main(String[] args) {

        System.out.println("Nama    :Santi Azhari");
        System.out.println("NIM     :12345");
        System.out.println("Alamat  :Gedong Jetis, Tulung, Tulung, Klaten");
        System.out.println("No.Telp :08560xxxxxxx");
        System.out.println("Email   :santi@gmail.com");
    }
}



2. PROGRAM 2
package pertemuan1_2;
public class PERTEMUAN1_2 {
    public static void main(String[] args) {

        System.out.print("Suatu saat perusahaan computer di dunia ");
        System.out.println("akan lebih dari lima dari sekarang.");
        System.out.println("Thomas Watson, IBM, 1943.");
    }
}



3. PROGRAM 3
package pertemuan1_3;
public class PERTEMUAN1_3 {
    public static void main(String[] args) {
        char kar;
       
        kar='A';
        System.out.print("Karakter adalah = ");
        System.out.println(kar);
       
        kar=70;
        System.out.print("Karakter Adalah = ");
        System.out.println(kar);
    }
}



4. PROGRAM 4
package pertemuan1_4;
public class PERTEMUAN1_4 {
    public static void main(String[] args) {
        int A=100, B=30;
        int jumlah = A+B;
        int kurang = A-B;
        int kali = A*B;
        float bagi = (float)A/B;
        int modulo = A%B;
       
        System.out.println("Penjumlahan: "+A+" + "+B+" = "+jumlah);
        System.out.println("Pengurangan: "+A+" - "+B+" = "+kurang);
        System.out.println("Perkalian: "+A+" * "+B+" = "+kali);
        System.out.println("Pembagian: "+A+" / "+B+" = "+bagi);
        System.out.println("Modulo: "+A+" mod "+B+" = "+modulo);
    }
}



5. PROGRAM 5
package pertemuan1_5;
public class PERTEMUAN1_5 {
    public static void main(String[] args) {
        int A=100, B=30;
       
        boolean lb = A>B;
        boolean lk = A<B;
        boolean lbs = A>=B;
        boolean lks = A<=B;
        boolean sm = A==B;
        boolean tsm = A!=B;
       
        System.out.println(A+" > "+B+" => "+lb);
        System.out.println(A+" < "+B+" => "+lk);
        System.out.println(A+" >= "+B+" => "+lbs);
        System.out.println(A+" <= "+B+" => "+lks);
        System.out.println(A+" = "+B+" => "+sm);
        System.out.println(A+" != "+B+" => "+tsm);
    }
}



6. PROGRAM 6
package pertemuan1_6;
public class PERTEMUAN1_6 {
    public static void main(String[] args) {
        int r=20, sisi=7, panjang=8,lebar=12;
        double phi =3.14;
                   
        double l_lingkaran = phi*r*r;
        int l_persegi = sisi*sisi;
        int l_persegipanjang = panjang*lebar;
       
       
        System.out.println("Luas Lingkaran adalah "+l_lingkaran);
        System.out.println("Luas Persegi adalah "+l_persegi);
        System.out.println("Luas Persegi Panjang adalah "+l_persegipanjang);
        System.out.println("Merci :)");
    }
}



7. PROGRAM 7
package tugas.pkg1;
public class TUGAS1 {
    public static void main(String[] args) {
        int nilai = 70;
       
        if (nilai>=60){
            System.out.println("Nilai = "+nilai+" lulus ujian");
        }
    }
}


8. PROGRAM 8
package tugas.pkg2;
public class TUGAS2 {
    public static void main(String[] args) {
        int pembelian = 110;
        System.out.println("Jumlah pembelian = "+pembelian);
       
        if (pembelian>=100){
            System.out.println("Diskon = 20% ");
        }
        else{
            System.out.println("Diskon 5%");
        }
    }
}



9. PROGRAM 9
package tugas.pkg3;
public class TUGAS3 {
    public static void main(String[] args) {
        double issurplus, salestotal, komisi;
        issurplus = 0;
        salestotal = 100000;
       
        if (issurplus ==0 ){
            if (salestotal < 10000000){
                komisi=0.02;
                System.out.println("komisi "+komisi);
            }
            else{
                komisi=0.04;
                 System.out.println("komisi "+komisi);
            }}
        else{
            if(salestotal < 10000000){
                komisi=0.03;
                System.out.println("komisi "+komisi);
            }
            else{
                komisi=0.06;
                System.out.println("komisi "+komisi);
            }}
    }
   
}



10. PROGRAM 10
package tugas.pkg4;
public class TUGAS4 {
    public static void main(String[] args) {

        int nilai;
        nilai = 75;
        System.out.println("Nilai = "+nilai);
       
        if(nilai>=80)
            System.out.println("Predikat A");
        else if(nilai>=69)
            System.out.println("Predikat B");
        else if(nilai>=56)
            System.out.println("Predikat C");
        else if(nilai>=40)
            System.out.println("Predikat D");
        else
            System.out.println("Predikat E");
    }
}



11. PROGRAM 11
package tugas.pkg5;
public class TUGAS5 {
    public static void main(String[] args) {
        int jumlah =9;
        for(int i=0;i<9;i++)
            System.out.println("Java");
    }
}



12. PROGRAM 12
package tugas.pkg6;
public class TUGAS6 {
    public static void main(String[] args) {
        int hari=2;
        switch (hari){
            case 1:
                System.out.println("Senin");
                break;
            case 2:
                System.out.println("Selasa");
                break;
            case 3:
                System.out.println("Rabu");
                break;
            case 4:
                System.out.println("Kamis");
                break;
            case 5:
                System.out.println("Jumat");
                break;
            case 6:
                System.out.println("Sabtu");
                break;
            case 7:
                System.out.println("Minggu");
                break;
        }
    }
}



13. PROGRAM 13
package tugas.pkg7;
import java.util.Scanner;
public class TUGAS7 {
    public static void main(String[] args) {
        Scanner anam = new Scanner(System.in);
        int fact=1, nilai;
       
        System.out.print("input bilangan : ");
        nilai = anam.nextInt();
        System.out.println("Bilangan Faktorial : "+nilai+"!");
       
        for (int i=nilai;i>0;--i){
            System.out.print(+i);
            if (i>1){
                System.out.print(" x ");}
            else{
                System.out.print(" ");}
            fact=fact*i;
        }
        System.out.println("= "+fact);}
    }
   


14. PROGRAM 14
package percobaan;
import java.util.Scanner;
public class PERCOBAAN {
    public static void main(String[] args) {
       
        Scanner scan = new Scanner(System.in);
        int angka;
        angka= scan.nextInt();
        System.out.println("Angka = "+angka);
    }
}



15. PROGRAM 15
package tugas.pkg1;
import java.util.Scanner;
public class TUGAS1 {
    public static void main(String[] args) {
        Scanner anam = new Scanner(System.in);
        int monthsinyear = 12;
        double annualinterestrate, loanamount, monthlyinterestrate, monthlypayment, totalpayment;
        int loanperiod, numberpayment;
        double atas, bawah, pangkat;
       
        System.out.print("Loan Amount (Rp.):  ");
        loanamount = anam.nextInt();
        System.out.print("Annual Interest Rate (%): ");
        annualinterestrate = anam.nextInt();
        System.out.print("Loan Period (Year): ");
        loanperiod  = anam.nextInt();
       
        monthlyinterestrate = (annualinterestrate/100)/monthsinyear;
        numberpayment = loanperiod * monthsinyear;
        atas = loanamount * monthlyinterestrate;
        bawah = (1/(1+monthlyinterestrate));
        pangkat = (double)Math.pow(bawah,numberpayment);
        monthlypayment = atas / (1-pangkat);
        totalpayment = monthlypayment * numberpayment;
       
        System.out.println("                                  ");
        System.out.println("==================================");
        System.out.println("Loan Amount (Rp.): "+loanamount);
        System.out.println("Annual Interest Rate (%): "+annualinterestrate);
        System.out.println("Loan Periode (Year): "+loanperiod);
        System.out.println("Monthly Payment (Rp): "+monthlypayment);
        System.out.println("Total Payment (Rp): "+totalpayment);
        System.out.println("==================================");
    }
}



16. PROGRAM 16
package tugas.pkg1;
import java.util.Scanner;
public class TUGAS1 {
    public static void main(String[] args) {
        Scanner anam = new Scanner(System.in);
        int monthsinyear = 12;
        double annualinterestrate, loanamount, monthlyinterestrate, monthlypayment, totalpayment;
        int loanperiod, numberpayment;
        double atas, bawah, pangkat;
       
        System.out.print("Loan Amount (Rp.):  ");
        loanamount = anam.nextInt();
        System.out.print("Annual Interest Rate (%): ");
        annualinterestrate = anam.nextInt();
        System.out.print("Loan Period (Year): ");
        loanperiod  = anam.nextInt();
       
        monthlyinterestrate = (annualinterestrate/100)/monthsinyear;
        numberpayment = loanperiod * monthsinyear;
        atas = loanamount * monthlyinterestrate;
        bawah = (1/(1+monthlyinterestrate));
        pangkat = (double)Math.pow(bawah,numberpayment);
        monthlypayment = atas / (1-pangkat);
        totalpayment = monthlypayment * numberpayment;
       
        System.out.println("                                  ");
        System.out.println("==================================");
        System.out.println("Loan Amount (Rp.): "+loanamount);
        System.out.println("Annual Interest Rate (%): "+annualinterestrate);
        System.out.println("Loan Periode (Year): "+loanperiod);
        System.out.println("Monthly Payment (Rp): "+monthlypayment);
        System.out.println("Total Payment (Rp): "+totalpayment);
        System.out.println("==================================");
    }
}



17. PROGRAM 17
package tugas2;
import java.util.Scanner;
public class TUGAS2 {
    public static void main(String[] args) {
        Scanner anam = new Scanner(System.in);
        double n, fn, operasi1, operasi2;
       
        System.out.print("Masukkan Bilangan : ");
        n = anam.nextInt();
        operasi1 = (1+ Math.sqrt(5)) / 2;
        operasi2 = (1- Math.sqrt(5)) / 2;
        fn = (1/Math.sqrt(5))*((Math.pow(operasi1,n))- (Math.pow(operasi2, n)));
       
        System.out.println("Hasil Bilangan Fibonanci = "+fn);
    }
}



18. PROGRAM 18
package tugas3;
import java.util.Scanner;
public class TUGAS3 {
    public static void main(String[] args) {
        Scanner anam = new Scanner (System.in);
        double d1, phi=3.14;
       
        System.out.println(Math.ceil(-157.2));
        System.out.println(Math.floor(-157.2));
        System.out.println(Math.ceil(157.2));
        System.out.println(Math.floor(157.2));
        System.out.println(Math.round(-157.2));
        System.out.println(Math.ceil(-157.7));
        d1=3*phi*Math.sin(Math.toRadians(187))+Math.abs(Math.cos(Math.toRadians(122)));
        System.out.println(+d1);
        double cos = Math.toDegrees(Math.acos(1/2));
        System.out.println(" A = "+cos);
    }
}



19. PROGRAM 19
package tugas.pkg4;
import java.util.Scanner;
public class TUGAS4 {
public static void main(String[] args) {
      String phoneStr;
      System.out.print("Masukan nomor hp anda: ");
      Scanner s = new Scanner(System.in);
      phoneStr = s.next();
      System.out.println(" ");
      System.out.print("No : " + phoneStr);
      char checkPola1 = phoneStr.charAt(3);
      char checkPola2 = phoneStr.charAt(7);
      char checkPola3 = phoneStr.charAt(8);
 
      int panjang = phoneStr.length();
      int syarat=0;
     
      for(int x=0;x<panjang;x++){
          char angka = phoneStr.charAt(x);
          if(angka == '1' || angka == '2' ||angka == '3' ||angka == '4' ||angka == '5' ||angka == '6' ||angka == '7' ||angka == '8' ||angka == '9' ||angka == '0' ||angka == '-'){
              syarat=1;
          }
          else{
              syarat=0;
              System.out.println(" TIDAK VALID!! ");
              break;
          }
        }
     
      if(syarat==1){
          if(checkPola1=='-'&&checkPola2=='-'){
                 System.out.println(" VALID!! ");
                }
          else if(checkPola1=='-'&&checkPola3=='-'){
                 System.out.println(" VALID!! ");
                }
          else{
                 System.out.println(" TIDAK VALID!! ");
                }
      }
    }
}



20. PROGRAM 20
package objectcasting;
class machine{
    public void start(){
        System.out.println("machine started");
    }
   
    public void end(){
        System.out.println("Manchine ended");
    }
}

class camera extends machine{
    public void start(){
        super.start();
        System.out.println("camera started");
    }
   
    public void snap(){
        System.out.println("photo taken");
    }
}
public class Objectcasting {
    public static void main(String[] args) {
        camera machine1 = new camera();
        //machine machine2 = new machine();
        //machine1.start();
       // (machine1)
        machine1.start();
        machine1.snap();
        machine1.end();
    }
}



21. PROGRAM 21
package animalsound;
class animal{
    public void animalsound(){
        System.out.println("default sound");
    }
}

public class Animalsound extends animal{
    public void animalsound(){
        System.out.println("woof");
    }

    public static void main(String[] args) {
        animal obj = new Animalsound();
        obj.animalsound();
    }
}



22. PROGRAM 22
package luas.dan.keliling;
import java.util.Scanner;

class bentuk{
    double luas, keliling;
    void hitungluas(){};
    void hitungkeliling(){};
}

class persegipanjang extends bentuk{
    int panjang, lebar;
    public persegipanjang(int p, int l){
        super();
        panjang=p;
        lebar=l;
    }
    public void hitungluas(){
        luas = panjang*lebar;
        System.out.println("Luas persegi panjang : "+luas);
    }
    public void hitungkeliling(){
        keliling = 2 * (panjang + lebar);
        System.out.println("Keliling persegi panjang : "+keliling);
    }
}

class lingkaran extends bentuk{
    int r;
    public lingkaran(){
        super();
    }
    public void setradius(int R) {
        r=R;
    }
    public void hitungluas(){
        luas = Math.PI*r*r;
        System.out.println("Luas lingkaran : "+luas);
    }
    public void hitungkeliling(){
        keliling = 2*Math.PI*r;
        System.out.println("Keliling lingkaran : "+keliling);
    }
}




23. PROGRAM 23
package luas.dan.keliling;
import java.util.Scanner;
public class hitung {
    Scanner input = new Scanner(System.in);
    static int counter =0;
    public void pilih() {
        int pilihan;
        System.out.println("=======DAFTAR MENU=======");
        System.out.println("1. Luas dan Keliling Lingkaran");
        System.out.println("2. Luas dan Keliling Persegi panjang");
        System.out.println("3. Keluar program");
        System.out.println("Pilihan Anda : ");
        pilihan=input.nextInt();
        luaskeliling(pilihan);
    } 
     public void luaskeliling(int x){
        if(x==1){
            int r;
            lingkaran a = new lingkaran();
            System.out.println("Jari-Jari Lingkaran : ");
            r=input.nextInt();
            a.setradius(r);
            a.hitungkeliling();
            a.hitungluas();
        }
        else if(x==2){
            int p,l;
            System.out.println("Panjang dan lebar persegi :");
            p=input.nextInt();
            l=input.nextInt();
            persegipanjang k = new persegipanjang(p,l);
            k.hitungluas();
            k.hitungkeliling();
        }
        else if(x==3){
            System.out.println("Terimakasih");
            System.exit(0);
        }
        else{
            System.out.println("Pilihan Salah!!");
        }
    }
   
    public static void main (String[] args){
        hitung x = new hitung();
        do{
            x.pilih();
        }while(counter==0);
    }
}



24. PROGRAM 24
public class siswa
{
    String nama = "Zahara ika";
    public static void main (String[] args){
        siswa nama = new siswa();
        System.out.print("nama siswa adalah "+nama.nama);
    }
}



25. PROGRAM 25
public class rumah
{
    public static void r_tamu(){
    System.out.println("Kursi, Meja, Vas");
    }
   
    void k_mandi(){
    System.out.println("bak, ember");
    }
}

public class isirumah
{
    public static void main (String [] args){
        rumah.r_tamu();
        rumah panggil = new rumah();
        panggil.k_mandi();
    }
}



26. PROGRAM 26
public class karyawan_master
{
    String nama, divisi;
}

public class karyawan
{
   public static void main(String[] args){
       //instansiasi 2 obyek referensi yang mengacu pada 1 obyek karyawan
       karyawan_master karyawan1 = new karyawan_master();
       karyawan_master karyawan2 = karyawan1;
     
       //mengisi data obyek karyawan melalui obyek referensi 1
       karyawan1.nama = "Mischele";
       karyawan1.divisi = "HRD";
     
       //mencetak data obyek karyawan di acu 2 obyek referensi
       System.out.println("data karyawan 1");
       System.out.println(""+karyawan1.nama);
       System.out.println(""+karyawan1.divisi);
       System.out.println("");
       System.out.println("data karyawan 2");
       System.out.println(""+karyawan2.nama);
       System.out.println(""+karyawan2.divisi);
    }
}



27. PROGRAM 27
public class kucing
{
    String nama;
    String warna;
    int berat;
}

public class kucingku_manis
{
    public static void main (String[] args){
    kucing kucingku = new kucing();
   
    kucingku.nama = "cepat";
    kucingku.warna = "merah";
    kucingku.berat = 15;
   
    System.out.println("nama kucingku : "+kucingku.nama);
    System.out.println("warna kucingku : "+kucingku.warna);
    System.out.println("berat kucingku : "+kucingku.berat);
    }
}



28. PROGRAM 28
public class balok
{
    double panjang, lebar, tinggi;
   
    void cetakvolume(){
        System.out.println("cetak volume = "+(panjang*lebar*tinggi));
    }
}

public class data
{
   public static void main (String [] args){
     
   balok b;
   b=new balok();
 
   b.panjang = 10;
   b.lebar = 10;
   b.tinggi = 10;
   b.cetakvolume();
    }
}



29. PROGRAM 29
public abstract class toko
{
    public toko(){
    }
   
    void barang(){
      }
}

public class beli extends toko
{
    public beli(){
    }
   
    void barang(){
        System.out.println("sandal melly beli");
    }
   
    void hargabeli(){
        System.out.println("Harga : RP. 7000");
    }
}

public class jual extends toko
{
   void barang(){
       System.out.println("sandal melly jual");
    }
   
    void hargajual(){
        System.out.println("Harga jual : Rp. 10.000");
    }
}

public class laporan
{
    public static void main(String [] args){
    beli beli = new beli();
    jual jual = new jual();
   
    System.out.println("harga beli barang : ");
    beli.barang();
    beli.hargabeli();
    System.out.println("harga jual barang : ");
    jual.barang();
    jual.hargajual();
}
}



30. PROGRAM 30
public abstract class human
{
    public human(){
    };
   
    void work(){
    };
   
    public abstract void hobi();
    public abstract void alamat();
}

public abstract class mahasiswa extends human
{
    public mahasiswa(){
    };
   
    public void hobi(){
    };
   
    public void alamat(){
    };
}

public class karyawan extends human
{
    public karyawan(){
    };
   
    public void alamat(){
      System.out.println("bandung");
    };
   
    public void work(){
        System.out.println("administrasi");
    };
   
    public void hobi(){
        System.out.println("reading");
    };
}

public abstract class dosen extends human
{
   public dosen(){
    };
   
   public void hobi(){
    };
   
    public void alamat(){
    };
}

public class maba extends mahasiswa
{
    public maba(){
    }
   
    public void alamat(){
    System.out.println("jogja");
    }
   
    public void hobi(){
    System.out.println("traveling");
    }
   
}

public class pasca extends mahasiswa
{
    public void namajurusan(){
        System.out.println("teknik");
    }
   
    public pasca(){
    }
   
    public void alamat(){
        System.out.println("bali");
    }
   
    public void hobi(){
        System.out.println("swimming");
    }
}

public class social extends dosen
{
    public social(){
    }
   
    public void hobi(){
        System.out.println("reading");
    }
   
    public void alamat(){
        System.out.println("ambon");
    }
}

public class science extends dosen
{
   public void namajurusan(){
       System.out.println("Mipa:");
    }
   
    public science(){
    }
   
    public void hobi(){
        System.out.println("waching movies");
    }
   
    public void alamat(){
        System.out.println("jakarta");
    }
}

public class mainclass
{
    public static void main(String [] args){
        maba maba = new maba();
        pasca pasca = new pasca();
        karyawan kr = new karyawan();
        science sc = new science();
        social soc = new social();
        System.out.println("class mahasiswa ");
        maba.hobi();
        maba.alamat();
        pasca.hobi();
        pasca.alamat();
        //pasca.namajurusan();
        System.out.println("class dosen");
        sc.hobi();
        sc.alamat();
        //sc.namajurusan();
        soc.hobi();
        soc.alamat();
        System.out.println("class karyawan");
        kr.work();
        kr.alamat();
    }
}



31. PROGRAM 31
public class phone
{
public String merk;
public int harga;

    public phone(){
    }
   
    public phone(String merk){
    this.merk=merk;
    }
   
    public phone(String merk, int harga){
    this.merk=merk;
    this.harga=harga;
    }
   
    public void isiphone(String merk){
    this.merk=merk;
    }
   
    public void isiphone(String merk, int harga){
    this.merk=merk;
    this.harga=harga;
    }
   
    public void lihatphone(){
    System.out.println("Merk : "+merk);
    System.out.println("Harga : "+harga);
    System.out.println(" ");
    }
}

public class demooverloading
{
    public static void main(String args []){
    System.out.println(" ");
    phone p1 = new phone();
    phone p2 = new phone("nokia");
    phone p3 = new phone ("sony ericson", 500);
   
    System.out.println("perbedaan output masing masing constructor");
    p1.lihatphone();
    p2.lihatphone();
    p3.lihatphone();
   
    phone p4, p5;
    p4 = new phone();
    p5 = new phone();
    p4.isiphone("Samsung");
    p5.isiphone("samsung", 5000);
    System.out.println("perbedaan output masing masing method");
   
    p4.lihatphone();
    p5.lihatphone();
    }
}



32. PROGRAM 32
public class secondmain
{
    public static void main(String[] args) {
        bicycle bike = new bicycle();
        account acct = new account( );
        String nama = "Jon Java";
        bike.setownername(nama);
        acct.setOwnerName(nama);
        acct.setInitialBalance(250.000);
        acct.add(25.00);
        acct.deduct(50);
       
        System.out.println(bike.getownername() + " adalah pemilik sepeda");
        System.out.println("dan memiliki Rp. " + acct.getCurrentBalance() +" di Bank.");
}
}

public class mainbicyleregistration
{
    public static void main(String[] args){
    bicycle anam1 = new bicycle();
    anam1.setownername("Adam smith pemilik sepeda 1");
   
    bicycle anam2 = new bicycle();
    anam2.setownername("Ben Jones pemilik sepeda 2");
   
    System.out.println(" "+anam1.getownername());
    System.out.println(" "+anam2.getownername());
    }
 }

public class account
{
    String ownerName;
    double balance;

    account(){
        ownerName = "Unassigned";
        balance = 0.0;
    }
   
    void add(double amt){
        balance = balance + amt;
    }

    void deduct(double amt){
        balance = balance - amt;
    }

    double getCurrentBalance(){
        return balance;
    }

    String getOwnerName(){
        return ownerName;
    }

    void setInitialBalance(double bal){
        balance = bal;
    }
   
    void setOwnerName(String nama){
        ownerName = nama;
    }
}

public class bicycle
{
    String ownername;
   
    bicycle(){
    String member= "unknown";
    }
   
    public String getownername(){
        return ownername;
    }

    public void setownername(String nama){
    ownername = nama;
    }
}



33. PROGRAM 33
public class Construktordinamis
{
    // instance variables - replace the example below with your own
    private int x;

       public Construktordinamis()
    {
        // initialise instance variables
        x = 0;
    }

    public int sampleMethod(int y)
    {
        // put your code here
        return x + y;
    }
}



34. PROGRAM 34
public class karyawan3
{
    String ID, nama, divisi;
    double gaji;
   
     //construktor kelas karyawan
    karyawan3(){
    ID = "K001";
    nama = "Budi";
    divisi = "Produksi";
    gaji = 1750000;
    }
   
    void cetakdata(){
        System.out.println("Data Karyawan ");
        System.out.println("ID : "+ID);
        System.out.println("Nama : "+nama);
        System.out.println("Divisi : "+divisi);
        System.out.println("Gaji : "+gaji);
    }
   
    double hitungsumbanganzakat(){
    double zakat = gaji * 0.025;
    return zakat;
}
}



35. PROGRAM 35
public class karyawan4
{
    String ID, nama, divisi;
    double gaji;
   
     //construktor kelas karyawan
    karyawan4(String kode, String Nama, String div, double Gaji){
    ID = kode;
    nama = Nama;
    divisi = div;
    gaji = Gaji;
    }
   
    void cetakdata(){
        System.out.println("Data Karyawan ");
        System.out.println("ID : "+ID);
        System.out.println("Nama : "+nama);
        System.out.println("Divisi : "+divisi);
        System.out.println("Gaji : "+gaji);
    }
   
    double hitungsumbanganzakat(){
    double zakat = gaji * 0.025;
    return zakat;
    }
}



36. PROGRAM 36
public class karyawan
{
    String ID, nama, divisi;
    double gaji;
   
    void cetakdata(){
        System.out.println("Data Karyawan ");
        System.out.println("ID : "+ID);
        System.out.println("Nama : "+nama);
        System.out.println("Divisi : "+divisi);
        System.out.println("Gaji : "+gaji);
    }
   
    double hitungsumbanganzakat(){
    double zakat = gaji * 0.025;
    return zakat;
}
}

public class methodvoid
{
    public static void main (String[] args){
    //intansiasi objek karyawan
    karyawan karyawan001 = new karyawan();
    //mengisi data pada objeck karyawan.
    karyawan001.ID="K001";
    karyawan001.nama="Agus Ramadhan";
    karyawan001.divisi="Keuangan";
    karyawan001.gaji= 1850000;
   
    ///menganngi method cetakdata()
    karyawan001.cetakdata();
}
}



37. PROGRAM 37
public class karyawan
{
    String ID, nama, divisi;
    double gaji;
   
    void cetakdata(){
        System.out.println("Data Karyawan ");
        System.out.println("ID : "+ID);
        System.out.println("Nama : "+nama);
        System.out.println("Divisi : "+divisi);
        System.out.println("Gaji : "+gaji);
    }
   
    double hitungsumbanganzakat(){
    double zakat = gaji * 0.025;
    return zakat;
}
}

public class methodnonvoid
{
     public static void main (String[] args){
    //intansiasi objek karyawan
    karyawan karyawan001 = new karyawan();
    //mengisi data pada objeck karyawan.
    karyawan001.ID="K001";
    karyawan001.nama="Agus Ramadhan";
    karyawan001.divisi="Keuangan";
    karyawan001.gaji= 1850000;
   
    ///menganngi method cetakdata()
    karyawan001.cetakdata();
    //memanggil menthod hitung sumbangan zakat;
    System.out.println("Sumbangan zakat : "+karyawan001.hitungsumbanganzakat());
}
}



38. PROGRAM 38
public class karyawan2
{
    String ID, nama, divisi;
    double gaji;
   
    void isidata (String kode, String Nama, String Div, double Gaji){
    ID = kode;
    nama = Nama;
    divisi = Div;
    gaji = Gaji;
    }
   
    void cetakdata(){
        System.out.println("Data Karyawan ");
        System.out.println("ID : "+ID);
        System.out.println("Nama : "+nama);
        System.out.println("Divisi : "+divisi);
        System.out.println("Gaji : "+gaji);
    }
   
    double hitungsumbanganzakat(){
    double zakat = gaji * 0.025;
    return zakat;
    } 
}

public class methodparameter
{
    public static void main(String[] args) {
        //instatiasi objek Karyawan
        karyawan2 karyawan001 = new karyawan2();

        mengisi data pada objek Karyawan
        melalui method isiData()*/
        karyawan001.isidata("k001", "Rommy", "Marketing", 2350000);

        //memanggil method cetakData();
        karyawan001.cetakdata();
    }

}



39. PROGRAM 39
public class hewan
{
    String ID, namahewan, keterangan, jenis;
   
    public void ID(){
    }
   
    public void namahewan(){
    }
   
    public void keterangan(){
    }
   
    public void jenis(){
    }
   
    public void cetakdata(){
    }
}

public class mamalia extends hewan
{
    String ID, namahewan, keterangan, jenis;
   
    public void ID(){
        ID="100";
    }
   
    public void namahewan(){
        namahewan="mamalia";       
    }
   
    public void keterangan(){
        keterangan="Merupakan hewan yang menyusui";
    }
   
    public void jenis(){
    }
   
    public void cetakdata(){
        System.out.println("ID = "+ID);
        System.out.println("Nama Hewan = "+namahewan);
        System.out.println("Keterangan = "+keterangan);
    }
}

public class sapi extends mamalia
{
    String ID, namahewan, keterangan, jenis;
   
    public void ID(){
        ID="101";
    }
   
    public void namahewan(){
        namahewan="Sapi";       
    }
   
    public void keterangan(){
        keterangan="Merupakan hewan berkaki empat dan menghasilkan susu";
    }
   
    public void jenis(){
        jenis="Mamalia";
    }
   
    public void cetakdata(){
        System.out.println("ID = "+ID);
        System.out.println("Nama Hewan = "+namahewan);
        System.out.println("Keterangan = "+keterangan);
        System.out.println("Jenis = "+jenis);
    }
}

public class kucing extends mamalia
{
     String ID, namahewan, keterangan, jenis;
   
    public void ID(){
        ID="120";
    }
   
    public void namahewan(){
        namahewan="Kucing";       
    }
   
    public void keterangan(){
        keterangan="Merupakan hewan berkaki empat yang pemalas";
    }
   
    public void jenis(){
        jenis="Mamalia";
    }
   
    public void cetakdata(){
        System.out.println("ID = "+ID);
        System.out.println("Nama Hewan = "+namahewan);
        System.out.println("Keterangan = "+keterangan);
        System.out.println("Jenis = "+jenis);
    }
}

public class anjing extends mamalia
{
   String ID, namahewan, keterangan, jenis;
   
    public void ID(){
        ID="130";
    }
   
    public void namahewan(){
        namahewan="Anjing";       
    }
   
    public void keterangan(){
        keterangan="Merupakan hewan yang paling setia";
    }
   
    public void jenis(){
        jenis="Mamalia";
    }
   
    public void cetakdata(){
        System.out.println("ID = "+ID);
        System.out.println("Nama Hewan = "+namahewan);
        System.out.println("Keterangan = "+keterangan);
        System.out.println("Jenis = "+jenis);
    }
}

public class anggora extends kucing
{
   String ID, namahewan, keterangan, jenis;
   
    public void ID(){
        ID="121";
    }
   
    public void namahewan(){
        namahewan="Anggora";       
    }
   
    public void keterangan(){
        keterangan="Memiliki bulu selembut sutera";
    }
   
    public void jenis(){
        jenis="Kucing";
    }
   
    public void cetakdata(){
        System.out.println("ID = "+ID);
        System.out.println("Nama Hewan = "+namahewan);
        System.out.println("Keterangan = "+keterangan);
        System.out.println("Jenis = "+jenis);
    }
}

public class persia extends kucing
{
    String ID, namahewan, keterangan, jenis;
   
    public void ID(){
        ID="122";
    }
   
    public void namahewan(){
        namahewan="Persia";       
    }
   
    public void keterangan(){
        keterangan="Merupakan jenis kucing berbulu panjang";
    }
   
    public void jenis(){
        jenis="Kucing";
    }
   
    public void cetakdata(){
        System.out.println("ID = "+ID);
        System.out.println("Nama Hewan = "+namahewan);
        System.out.println("Keterangan = "+keterangan);
        System.out.println("Jenis = "+jenis);
    }
}

public class tiffany extends kucing
{
    String ID, namahewan, keterangan, jenis;
   
    public void ID(){
        ID="123";
    }
   
    public void namahewan(){
        namahewan="Tiffany";       
    }
   
    public void keterangan(){
        keterangan="Ras kucing ini ditemukan tahun 1967 di new york";
    }
   
    public void jenis(){
        jenis="Kucing";
    }
   
    public void cetakdata(){
        System.out.println("ID = "+ID);
        System.out.println("Nama Hewan = "+namahewan);
        System.out.println("Keterangan = "+keterangan);
        System.out.println("Jenis = "+jenis);
    }
}

public class cihuahua extends anjing
{
    String ID, namahewan, keterangan, jenis;
   
    public void ID(){
        ID="133";
    }
   
    public void namahewan(){
        namahewan="CiHuaHua";       
    }
   
    public void keterangan(){
        keterangan="Ras Anjing terkecil dan nama negara bagian Cihuahua di Meksiko";
    }
   
    public void jenis(){
        jenis="Anjing";
    }
   
    public void cetakdata(){
        System.out.println("ID = "+ID);
        System.out.println("Nama Hewan = "+namahewan);
        System.out.println("Keterangan = "+keterangan);
        System.out.println("Jenis = "+jenis);
    }
}

public class golden extends anjing
{
    String ID, namahewan, keterangan, jenis;
   
    public void ID(){
        ID="132";
    }
   
    public void namahewan(){
        namahewan="Golden";       
    }
   
    public void keterangan(){
        keterangan="Merupakan anjing intelijen yang serba guna";
    }
   
    public void jenis(){
        jenis="Anjing";
    }
   
    public void cetakdata(){
        System.out.println("ID = "+ID);
        System.out.println("Nama Hewan = "+namahewan);
        System.out.println("Keterangan = "+keterangan);
        System.out.println("Jenis = "+jenis);
    }
}

public class pom extends anjing
{
    String ID, namahewan, keterangan, jenis;
   
    public void ID(){
        ID="131";
    }
   
    public void namahewan(){
        namahewan="Pom";       
    }
   
    public void keterangan(){
        keterangan="Merupakan jenis anjing besar Spitz Jerman.";
    }
   
    public void jenis(){
        jenis="Anjing";
    }
   
    public void cetakdata(){
        System.out.println("ID = "+ID);
        System.out.println("Nama Hewan = "+namahewan);
        System.out.println("Keterangan = "+keterangan);
        System.out.println("Jenis = "+jenis);
    }
}

public class reptile extends hewan
{
    String ID, namahewan, keterangan, jenis;
   
    public void ID(){
        ID="200";
    }
   
    public void namahewan(){
        namahewan="Reptil";       
    }
   
    public void keterangan(){
        keterangan="Merupakan hewan vertebrata yang berdarah dingin";
    }
   
    public void jenis(){
    }
   
    public void cetakdata(){
        System.out.println("ID = "+ID);
        System.out.println("Nama Hewan = "+namahewan);
        System.out.println("Keterangan = "+keterangan);
    }
}

public class ular extends reptile
{
    String ID, namahewan, keterangan, jenis;
   
    public void ID(){
        ID="210";
    }
   
    public void namahewan(){
        namahewan="Ular";       
    }
   
    public void keterangan(){
        keterangan="Digolongkan dalam reptil bersisik.";
    }
   
    public void jenis(){
        jenis="Reptil";
    }
   
    public void cetakdata(){
        System.out.println("ID = "+ID);
        System.out.println("Nama Hewan = "+namahewan);
        System.out.println("Keterangan = "+keterangan);
        System.out.println("Jenis = "+jenis);
    }
}

public class buaya extends reptile
{
    String ID, namahewan, keterangan, jenis;
   
    public void ID(){
    }
   
    public void namahewan(){
    }
   
    public void keterangan(){
    }
   
    public void jenis(){
    }
   
    public void cetakdata(){
    }
}

public class cicak extends reptile
{
    String ID, namahewan, keterangan, jenis;
   
    public void ID(){
    }
   
    public void namahewan(){
    }
   
    public void keterangan(){
    }
   
    public void jenis(){
    }
   
    public void cetakdata(){
    }
}

public class kobra extends ular
{
    String ID, namahewan, keterangan, jenis;
   
    public void ID(){
    }
   
    public void namahewan(){
    }
   
    public void keterangan(){
    }
   
    public void jenis(){
    }
   
    public void cetakdata(){
    }
}

public class phyton extends ular
{
    String ID, namahewan, keterangan, jenis;
   
    public void ID(){
    }
   
    public void namahewan(){
    }
   
    public void keterangan(){
    }
   
    public void jenis(){
    }
   
    public void cetakdata(){
    }
}

public class mainclass
{
    public static void main(String args []){
    mamalia mamaliaku = new mamalia();
    sapi sapiku = new sapi();
    kucing kucingku = new kucing();
    anggora anggoraku = new anggora();
    persia persiaku = new persia();
    tiffany tiffaniku = new tiffany();
    anjing anjingku = new anjing();
    pom pomku = new pom();
    golden goldenku = new golden();
    cihuahua cihuahuaku = new cihuahua();
    reptile reptilku = new reptile();
    ular ularku = new ular();
   
    System.out.println("Berikut daftar klasifikasi hewan beserta contoh rasnya: ");
    System.out.println(" ");
    mamaliaku.ID();
    mamaliaku.namahewan();
    mamaliaku.keterangan();
    mamaliaku.jenis();
    mamaliaku.cetakdata();
    System.out.println(" ");
   
    sapiku.ID();
    sapiku.namahewan();
    sapiku.keterangan();
    sapiku.jenis();
    sapiku.cetakdata();
    System.out.println(" ");
   
    kucingku.ID();
    kucingku.namahewan();
    kucingku.keterangan();
    kucingku.jenis();
    kucingku.cetakdata();
    System.out.println(" ");

    anggoraku.ID();
    anggoraku.namahewan();
    anggoraku.keterangan();
    anggoraku.jenis();
    anggoraku.cetakdata();
    System.out.println(" ");

    persiaku.ID();
    persiaku.namahewan();
    persiaku.keterangan();
    persiaku.jenis();
    persiaku.cetakdata();
    System.out.println(" ");

    tiffaniku.ID();
    tiffaniku.namahewan();
    tiffaniku.keterangan();
    tiffaniku.jenis();
    tiffaniku.cetakdata();
    System.out.println(" ");

    anjingku.ID();
    anjingku.namahewan();
    anjingku.keterangan();
    anjingku.jenis();
    anjingku.cetakdata();
    System.out.println(" ");

    pomku.ID();
    pomku.namahewan();
    pomku.keterangan();
    pomku.jenis();
    pomku.cetakdata();
    System.out.println(" ");

    goldenku.ID();
    goldenku.namahewan();
    goldenku.keterangan();
    goldenku.jenis();
    goldenku.cetakdata();
    System.out.println(" ");

    cihuahuaku.ID();
    cihuahuaku.namahewan();
    cihuahuaku.keterangan();
    cihuahuaku.jenis();
    cihuahuaku.cetakdata();
    System.out.println(" ");

    reptilku.ID();
    reptilku.namahewan();
    reptilku.keterangan();
    reptilku.jenis();
    reptilku.cetakdata();
    System.out.println(" ");

    ularku.ID();
    ularku.namahewan();
    ularku.keterangan();
    ularku.jenis();
    ularku.cetakdata();
    System.out.println(" ");   
    }
}



40. PROGRAM 40
public class segitiga
{
    double setalas, settinggi;
    double luas;
   
    public void setalas(int alas){
        setalas=alas;
    }
   
    public void settinggi(int tinggi){
        settinggi=tinggi;
    }
   
    double luas(){
        luas = (setalas*settinggi)/2;
        return luas;
    }
   
}

public class lingkaran
{
    int setr;
    double luas;
   
    public void setr(int r){
        setr = r;
    }
   
    double luas(){
        luas = 3.14*setr*setr;
        return luas;
    }
}

public class belahketupat
{
    double setd1, setd2;
    double luas;
   
    public void setd1(double d1){
        setd1=d1;
    }
   
    public void setd2(double d2){
        setd2=d2;
    }
   
    double luas(){
        luas=(setd1*setd2)/2;
        return luas;
    }
}

public class tugas2
{
    public static void main (String args []){
    lingkaran anaml = new lingkaran();
    segitiga anams = new segitiga();
    belahketupat anamb = new belahketupat();
   
    anaml.setr(20);
    System.out.println("Luas Lingkaran      : "+anaml.luas());
   
    anams.setalas(7);
    anams.settinggi(15);
    System.out.println("Luas Segitiga       : "+anams.luas());
   
    anamb.setd1(8);
    anamb.setd2(10);
    System.out.println("Luas BelahKetupat   : "+anamb.luas());
   
    double luastotal;
    luastotal = (anaml.luas()-anams.luas()-anamb.luas());
    System.out.println(" ");
    System.out.println("Luas Total          : "+luastotal);
    }
}



41. PROGRAM 41
package enkapsulasi.pkg1;
class encapsulationdemo{
    private int ssn;
    private String empname;
    private int empage;
   
    //getter and setter methods
    public int getempssn(){
        return ssn;
    }
   
    public String getempname(){
        return empname;
    }
   
    public int getempage(){
        return empage;
    }
   
    public void setempage (int newvalue){
        empage = newvalue;
    }
   
    public void setempname(String newvalue){
        empname = newvalue;
    }
   
    public void setempssn(int newvalue){
        ssn = newvalue;
    }
}

public class Enkapsulasi1 {

        public static void main(String[] args) {
            encapsulationdemo obj = new encapsulationdemo();
            obj.setempname("mario");
            obj.setempage(32);
            obj.setempssn(112233);
            System.out.println("employee name : "+obj.getempname());
            System.out.println("employee ssn : "+obj.getempssn());
            System.out.println("employee age : "+obj.getempage());
    }
}



42. PROGRAM 42
package enkapsulasi.pkg2;
class musikpop{
    private String judullagu;
    protected void setjudul(String nama){
        judullagu=nama;
    }
   
    protected String getjudul(){
        return judullagu;
    }
}

class musikjpop extends musikpop{
    private int tahunterbit;
    musikjpop(String judul, int tahun){
        setjudul(judul);
        tahunterbit=tahun;
    }
   
    public void showdata(){
        System.out.println("Judul lagu jpop : "+getjudul());
        System.out.println("tahun terbit : "+tahunterbit);
    }
}

class musikjazz{
    private String penyanyi;
    public void setpenyanyi(String nama){
        penyanyi = nama;
    }
   
    public String getpenyanyi(){
        return penyanyi;
    }
   
    public void showpenyanyi(){
        System.out.println("penyanyi : "+penyanyi);
    }
}

public class Enkapsulasi2 {

    public static void main(String[] args) {
       musikjpop obj = new musikjpop("I feel my soul",2008);
       obj.showdata();
       obj.setjudul("separuh aku");
        System.out.println("judul lagu : "+obj.getjudul());
    }
}



43. PROGRAM 43
package enkapsulasi.pkg3;
class mahasiswa{
    int nim;
    public String nama;
    private double ipk;
    public void setipk(double nilai){
        ipk=nilai;
    }
   
    public double getipk(){
        return ipk;
    }
}

public class Enkapsulasi3 {
    public static void main(String[] args) {
        mahasiswa yahya = new mahasiswa();
        yahya.nim = 1009;
        yahya.nama = "yahya al - mahandiz";
        yahya.setipk(3.77);
        System.out.println("NIM : "+yahya.nim);
        System.out.println("Nama : "+yahya.nama);
        System.out.println("IPK : "+yahya.getipk()); 
    }
}



44. PROGRAM 44
package program.menghitung.sudut.vektor;
Support By Khaerul Anam
 *Support By Khaerul Anam
 *Support By Khaerul Anam
 *Support By Khaerul Anam
 *Support By Khaerul Anam
 */
import java.util.Scanner;
class variabel{
double x1,  x2, x3, x4, y1, y2, y3, y4;
double a31, a42, b31, b42;
double uxv, uu, vv, cos;
}

class vektor extends variabel{

public void setvektor1(double a,double b){
    x1=a;
    y1=b; 
}

public void setvektor2(double c, double d){
    x2=c;
    y2=d;
}

public void setvektor3(double e, double f){
    x2=e;
    y3=f;
}

public void setvektor4(double g, double h){
    x4=g;
    y4=h;
}

public void hitungvektorposisi(){
    uxv = (x1*x2)+(y1*y2);
    uu = Math.sqrt(((x1*x1)+(y1*y1)));
    vv = Math.sqrt((x2*x2)+(y2*y2));
    cos = Math.toDegrees(Math.acos(uxv / (uu*vv)));
    System.out.println("X1 = "+x1+" Y1 = "+y1);
    System.out.println("X2 = "+x2+" Y2 = "+y2);
    System.out.println("U.V = "+uxv);
    System.out.println("|U| : "+uu);
    System.out.println("|V| : "+vv);
    System.out.println("Sudut Vektor = (U.V) / (|U|.|V|)");
    System.out.println("Sudut Vektornya : "+cos);
}

public void hitungvektorbukanposisi(){
    a31 = x2-x1;
    a42 = y2-y1;
    b31 = x4-x3;
    b42 = y4-y3;
   
    // vektor1 = (a31, a42)
    // vektor2 = (b31, b42)
    uxv = (a31*b31)+(a42*b42);
    uu = Math.sqrt(((a31*a31)+(a42*a42)));
    vv = Math.sqrt((b31*b31)+(b42*b42));
    cos = Math.toDegrees(Math.acos(uxv / (uu*vv)));
    System.out.println("X1 = "+x1+" Y1 = "+y1);
    System.out.println("X2 = "+x2+" Y2 = "+y2);
    System.out.println("X3 = "+x3+" Y3 = "+y3);
    System.out.println("X4 = "+x4+" Y4 = "+y4);
    System.out.println("U.V = "+uxv);
    System.out.println("|U| : "+uu);
    System.out.println("|V| : "+vv);
    System.out.println("Sudut Vektor = (U.V) / (|U|.|V|)");
    System.out.println("Sudut Vektornya : "+cos);
}
}

public class ProgramMenghitungSudutVektor {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        vektor main = new vektor();
        double x1, x2, x3, x4, y1, y2, y3, y4;
        int pil1=1, pil2;
               
        while (pil1==1){
            System.out.println("============PROGRAM START============");
            System.out.print("Apakah vektor posisi(1=YA ATAU 2=TIDAK)? : ");
            pil2 = input.nextInt();
           
            if(pil2 == 1){
                System.out.print("Masukkan x1 : ");
                x1=input.nextDouble();
                System.out.print("Masukkan y1 : ");
                y1=input.nextDouble();
                System.out.print("Masukkan x2 : ");
                x2=input.nextDouble();
                System.out.print("Masukkan y2 : ");
                y2=input.nextDouble();
                main.setvektor1(x1,y1);
                main.setvektor2(x2,y2);
                main.hitungvektorposisi();
            }
            else if(pil2 == 2){
                System.out.print("Masukkan x1 : ");
                x1=input.nextDouble();
                System.out.print("Masukkan y1 : ");
                y1=input.nextDouble();
                System.out.print("Masukkan x2 : ");
                x2=input.nextDouble();
                System.out.print("Masukkan y2 : ");
                y2=input.nextDouble();
                System.out.print("Masukkan x3 : ");
                x3=input.nextDouble();
                System.out.print("Masukkan y3 : ");
                y3=input.nextDouble();
                System.out.print("Masukkan x4 : ");
                x4=input.nextDouble();
                System.out.print("Masukkan y4 : ");
                y4=input.nextDouble();
                main.setvektor1(x1,y1);
                main.setvektor2(x2,y2);
                main.setvektor3(x3,y3);
                main.setvektor4(x4,y4);
                main.hitungvektorbukanposisi();
            }
            else{
                System.out.println("Pilihan Anda Tidak Tersedia!!!");
            }
            System.out.println("");
            System.out.println("HITUNG LAGI ?? MASUKKAN 1=YA ATAU 2=TIDAK");
            System.out.print("Pilihan anda : ");
            pil1 = input.nextInt();
        }
        System.out.println("----------////==========");
        System.out.println("Program dihentikan!!!");
    }
   
}



45. PROGRAM 45
public class A
{
    public void methodA(){
        System.out.println("Base class method");
   
    }
}

public class B extends A
{
    public void methodB(){
    System.out.println("child class method");
    }
   
    public static void main (String args[]){
    B obj = new B();
    obj.methodA();
    obj.methodB();
    }
}



46. PROGRAM 46
public class car
{
    public car(){
    System.out.println("class car");
    }
   
    public void vehicletype(){
    System.out.println("vehicle type : car");
    }
}

public class maruti extends car
{
    public maruti(){
    System.out.println("class maruti");
    }
   
    public void brand(){
    System.out.println("brand : maruti");
    }
   
    public void speed(){
    System.out.println("max : 90 Kmph");
    }
}



47. PROGRAM 47
public class A2
{
    public void methodA2(){
    System.out.println("class A methodA");
    }
}

public class B2 extends A2
{
    public void methodA2(){
    System.out.println("child class B is overriding inherited method A");
    }
   
    public void methodB2(){
    System.out.println("class B methodB");
    }
}

public class C extends A2
{
    public void methodA2(){
    System.out.println("child class C is overriding the methodA");
    }
   
    public void methodC(){
    System.out.println("class C methodC");
    }
}

public class D extends B2
{
    public void methodD(){
    System.out.println("class D methodD");
    }
   
    public static void main(String args[]){
    D obj = new D();
    obj.methodD();
    obj.methodA2();
    }
}



48. PROGRAM 48
public class A
{
   public void methodA(){
    System.out.println("method of class A");
    }
}

public class B extends A
{
    public void methodB(){
    System.out.println("method of class B");
    }
}

public class C extends A
{
   public void methodC(){
    System.out.println("method of class C");
    }
}

public class D extends A
{
    public void methodD(){
    System.out.println("method of class D");
    }
}

public class myclass
{
    public void methodB(){
    System.out.println("method of class B");
    }
   
    public static void main(String args[]){
    B obj1 = new B();
    C obj2 = new C();
    D obj3 = new D();
    obj1.methodA();
    obj2.methodA();
    obj3.methodA();
    }
}



49. PROGRAM 49
public class dosen
{
    protected String nama;
    protected String nik;
    protected String jurusan;
   
    dosen(String namaX, String nikX, String jurX){
    nama = namaX;
    nik = nikX;
    jurusan = jurX;
    }
   
    public void view(){
    System.out.println("nama : "+nama);
    System.out.println("nik : "+nik);
    System.out.println("jurusan : "+jurusan);
    }
}

public class dekan extends dosen
{
    private String fakultas;
   
    dekan(String namaX, String nikX, String jurX, String fakX){
    super (namaX, nikX, jurX);
    fakultas = fakX;
    }
   
    public void viewdekan(){
    System.out.println("Fakultas : "+fakultas);
    }
}

public class rektor extends dosen
{
    private int th_mulai;
    private int jabatan_ke;
   
    rektor (String namaX, String nikX, String jurX, int thX, int keX){
        super(namaX, nikX, jurX);
        th_mulai = thX;
        jabatan_ke = keX;
    }
   
    public void viewrektor(){
    System.out.println("Th mulai jabatan : "+th_mulai);
   
    System.out.println("jabatan rektor ke : "+jabatan_ke);
    }
}

public class kalab extends dosen
{
    private String laboratorium;
   
    kalab(String namaX, String nikX, String jurX, String labX){
    super(namaX, nikX, jurX);
    laboratorium = labX;
    }
   
    public void viewkalab(){
    System.out.println("laboratorium : "+laboratorium);
    }
}

public class main
{
    public static void main(String args[]){
    rektor rek = new rektor("Ahmad", "005343594", "Informatika", 2006, 2);
   
    dekan dek = new dekan("Dina","932221234","T. Kimia","TI");
   
    kalab lab = new kalab("Indah","068336234","Informatika","KSC");
   
    rek.view();
    rek.viewrektor();
    dek.view();
    dek.viewdekan();
    lab.view();
    lab.viewkalab();
    }
}



50. PROGRAM 50
public interface A
{
    public void methodA();
}

public interface B extends A
{
    public void methodB();
}

public interface C extends A
{
    public void methodC();
}

public class D implements B, C
{
    public void methodA(){
    System.out.println("methodA");
    }
   
     public void methodB(){
    System.out.println("methodB");
    }
   
     public void methodC(){
    System.out.println("methodC");
    }
}

public class main
{
    public static void main(String args[]){
        D obj1 = new D();
       
        obj1.methodA();
        obj1.methodB();
        obj1.methodC();
    }
}



51. PROGRAM 51
public class pegawai
{
    private String nip, nama, alamat;
    protected String jabatan;
    protected int gaji;
   
    protected pegawai (String ni, String na, String al){
        nip = ni;
        nama = na;
        alamat = al;
    }
    protected String getnama(){
        return nama;
    }
    protected int getgaji(){
        return gaji;
    }
    protected String getjabatan(){
        return jabatan;
    }
}

public class staff extends pegawai
{
   private int jumlahlembur, jumlahkehadiran, upahharian, upahlembur;
 
   public staff(String ni, String na, String al){
      super(ni, na, al);
   }
   public void setkehadiran(int hadir){
      jumlahkehadiran = hadir;
    }
   public void setlembur(int lembur){
       jumlahlembur = lembur;
    }
   public int getgaji(){
       int gajistaff = 3000000;
       int insentifstaff = 50000;
       int bonusstaff = 100000;
       upahharian = jumlahkehadiran * insentifstaff;
       upahlembur = jumlahlembur * bonusstaff;
       int gajitotal = upahharian + upahlembur + gajistaff;
       gaji=gajitotal;
       return  gaji;
    }
    public String getjabatan(){
        return "staff";
    }
}

public class manager extends pegawai
{
    private int jumlahkehadiran, upahharian;
   
    public manager (String ni, String na, String al){
        super(ni, na, al);
    }
    public void setkehadiran(int hadir){
      jumlahkehadiran = hadir;
    }
    public int getgaji(){
      int gajimanager = 5000000;
      int insentifmanager = 50000;
      int upaharian = jumlahkehadiran * insentifmanager;
      int gajitotal = upaharian + gajimanager;
      gaji = gajitotal;
      return gaji;
    }
    public String getjabatan(){
        return "manager";
    }
}

public class daftargaji
{
    public int n;
    public pegawai arrdata[];
 
   public daftargaji(int count){
       arrdata = new pegawai[count];
    }
   public void tambahpegawai(pegawai a){
       arrdata[n] = a;
     
       n++;   
    }
   public void cetaksemuagaji(){
       System.out.println ("DAFTAR PENGGAJIAN BULAN INI");
       System.out.println ("=======================================");
       for(int i=0; i<n; i++){
           System.out.println ("Nama            : "+arrdata[i].getnama());
           System.out.println ("Jabatan         : "+arrdata[i].getjabatan());
           System.out.println ("Total gaji      : "+arrdata[i].getgaji());
           System.out.println ("");
           System.out.println ("");
        }
   }
}

public class main
{
    public static void main (String args[]){
    staff anam1 = new staff("1234", "Rani", "Boyolali");
    anam1.setkehadiran(28);
    anam1.setlembur(10);
    anam1.getgaji();
   
    manager anam2 = new manager("4567", "Sandi", "Klaten");
    anam2.setkehadiran(28);
    anam2.getgaji();
   
    staff anam3 = new staff("12345", "Zendi", "Boyolali");
    anam3.setkehadiran(28);
    anam3.setlembur(15);
    anam3.getgaji();
   
    manager anam4 = new manager("45678", "Afin", "Klaten");
    anam4.setkehadiran(30);
    anam4.getgaji();
   
    daftargaji MasterAnam = new daftargaji(5);
    MasterAnam.tambahpegawai(anam1);
    MasterAnam.tambahpegawai(anam2);
    MasterAnam.tambahpegawai(anam3);
    MasterAnam.tambahpegawai(anam4);
    MasterAnam.cetaksemuagaji();
}
}



52. PROGRAM 52
package polimorfisme.pkg2;
class kendaraan{
private String model;
public kendaraan(String model){
    this.model = model;
}
public void informasi(){}
}

class pesawat extends kendaraan{
    private String nama;
    private String jenis;
   
    public pesawat (String nama){
        super("pesawat");
        this.nama=nama;
        jenis = "belum teridentifikasi";
               
    }
    public pesawat(String nama, String jenis){
        super("pesawat");
        this.nama=nama;
        this.jenis=jenis;
    }
   
    public void informasi(){
        System.out.println("Nama pesawat adalah "+nama);
        System.out.println("Jenis pesawat adalah "+jenis);
    }
}

class mobil extends kendaraan{
    private String nama;
    private String jenis;
   
    public mobil(String nama){
        super("Mobil");
        this.nama=nama;
        jenis="belum terindifikasi";
    }
   
    public mobil(String nama, String jenis){
        super("Mobil");
        this.nama = nama;
        this.jenis=jenis;
    }
   
    public void informasi(){
        System.out.println("Nama Mobil adalah "+nama);
        System.out.println("Jenis mobil adalah "+jenis);
    }
}

class kapal extends kendaraan{
    private String nama;
    private String jenis;
   
    public kapal(String nama, String jenis){
        super("kapal");
        this.nama=nama;
        this.jenis="belum teridentifikasi";
    }
 
public void informasi(){
    System.out.println("Nama kapal adalah "+nama);
    System.out.println("Jenis kapal adalah "+jenis);
}
}

public class Polimorfisme2 {
    public static void main(String[] args) {
        kendaraan P;
        pesawat psw = new pesawat("Boeng 707","Pesawat Komersial");
        mobil mbl1 = new mobil("toyota kijang", "jeep");
        mobil mbl2 = new mobil("suzuki baleno","sedan");
        mobil mbl3 = new mobil("VW scembi");
        kapal kpl = new kapal("queen mary 2", "kapal pesiar");
       
        P = psw;
        P.informasi();
        P=mbl1;
        P.informasi();
        P=mbl2;
        P.informasi();
        P=mbl3;
        P.informasi();
        P=kpl;
        P.informasi();
    }
}



53. PROGRAM 53
package polimorfisme.pkg1;
class binatang{
    public void info(){
        System.out.println("Info tentang hewan : ");
    }
}

class herbivora extends binatang{
    public void info(){
        System.out.println("Info pada herbivora : memakan makanan berupa tumbuh tumbuhan");
    }
}

class kelinci extends herbivora{
    public void info(){
        System.out.println("Info pada kelinci : memakan makanan berupa wortel");
    }
}

public class Polimorfisme1 {
public static void main (String args[]){
    herbivora herbivoraku;
    kelinci kelinciku;
    binatang hewan;
   
    herbivoraku = new herbivora();
    kelinciku = new kelinci();
    hewan=herbivoraku;
    hewan.info();
    hewan=kelinciku;
    hewan.info();
}   
}



54. PROGRAM 54
public class Person
{
    private String name;
    private String address;
    private double penghasilan;
    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name = name;
    }
    public String getAddress(){
        return address;
    }
    public void setAddress(String address){
        this.address = address;
    }
    public void setPenghasilan(double penghasilan){
        this.penghasilan = penghasilan;
    }
    public double getPenghasilan(){
        return penghasilan;
    }
}

public class Student extends Person
{
   private String school;
    private double grade;
    public String getSchool(){
        return school;
    }
    public void setSchool(String school){
        this.school = school;
    }
    public void setGrade(double grade){
        this.grade = grade;
    }
    public double getgrade(){
        return grade;
    }

}

public class Teacher extends Person
{
    private String subject;
    private int position;
    private double penghasilan;
    public String getSubject(){
        return subject;
    }
    public void setSubject(String subject){
        this.subject = subject;
    }
    public int getPosition(){
        return position;
    }
    public void setPosition(int position){
        this.position = position;
    }
    public void setPenghasilan(double penghasilan){
        if(getPosition()==1){
            this.penghasilan = penghasilan + 5000000;
        }
        else if (getPosition()==2){
             this.penghasilan = penghasilan + 3500000;
    }
     else {
         this.penghasilan = penghasilan;
}
super.setPenghasilan(this.penghasilan);
}
}

public class InternationalStudent extends Student
{
    public InternationalStudent(){
    }
   
    private String country;
    public String getCountry(){
        return country;
    }
    public void setCountry(String country){
        this.country = country;
    }
}
import java.text.DecimalFormat;
public class MainTester
{
    public static void main (String[] args){
        Person person1 = new Person();
        Student student1 = new Student();
        InternationalStudent inter1 = new InternationalStudent();
        Teacher teacher1 = new Teacher();
        person1.setName("Tom Jones");
        student1.setName("CCR");
        student1.setSchool("Lexington High");
        inter1.setName("Bill Clington");
        inter1.setSchool("Lexington High");
        inter1.setCountry("Korea");
        teacher1.setName("Beatles");
        teacher1.setSubject("History");
        teacher1.setPosition(1);
        teacher1.setPenghasilan(7000000);
       
        System.out.println("Displaying name of all object instances");
        System.out.println("Person1.getName() = " + person1.getName());
        System.out.println("Student1.getName() = " + student1.getName());
        System.out.println("InternationalStudent1.getName() = " + inter1.getName());
        System.out.println("Teacher1.getName() = " + teacher1.getName());
       
        System.out.println("Person1.getPenghasilan() = " + person1.getPenghasilan());
        System.out.println("Student1.getPenghasilan() = " + student1.getPenghasilan());
        System.out.println("InternationalStudent1.getPenghasilan() = " + inter1.getPenghasilan());
        System.out.println("Teacher1.getPenghasilan() = " + new DecimalFormat(" ").format(teacher1.getPenghasilan()));
}
}



55. PROGRAM 55
public interface Washable
{
    public  abstract void wash();
}
public class Vegetable implements Washable
{
    public void wash(){
    //implementation
    }
}
public class Cloth implements Washable
{
    public void wash(){
    //implementation
    }
}



56. PROGRAM 56
interface programmer{
    void memprogram();
}
interface burung{
    void terbang();
    void buangkotoran();
}interface tentara{
    void menembak();
}class superman implements programmer,tentara,burung {
    public void memprogram(){
        System.out.println("Implementasi memprogram... tak... tik");
    }
   
    public void menembak(){
        System.out.println("Implementasi menembak... dor.. dor");
    }
   
    public void terbang(){
        System.out.println("Implementasi terbang.. zap...........");
    }
   
    public void buangkotoran(){};
}public class bejo{
    public static void main (String args[]){
        superman bj = new superman();
        bj.memprogram();
        bj.menembak();
        bj.terbang();
    }
}



57. PROGRAM 57
public interface Weight{
    public void setWeight(int weight);
    public int getWeight();
}
public class Person implements Weight
{
    private int weight;
    public String name;
   
    public void setWeight(int weight){
    this.weight = weight;
    }
   
    public void setName(String nama){
    name = nama;
    }
   
    public int getWeight(){
    return weight;
    }
}
public class Car implements Weight
{
   int weight;
 
   public void setWeight(int weight){
    this.weight = weight;
    }
   
    public int getWeight(){
    return weight;
    }
}

public class MainTester
{
    public static void main (String args[]){
    Person person1 = new Person();
    person1.setName("Tom Jones");
    person1.setWeight(65);
   
    Car car1 = new Car();
    car1.setWeight(1270);
   
    System.out.println("person1.setWeight() = "+person1.getWeight());
    System.out.println("car1.setWeight() = "+car1.getWeight());
   
    }
}

public class MainTester2
{
    public static void main (String args[]){
       
    Weight iweight;
    //class to interface
    Person person1 = new Person();
    iweight  = person1;
    person1.setWeight(65);
    System.out.println("person1.setWeight() = "+person1.getWeight());
   
    //interface to class
    Person p1 = (Person) iweight;
    p1.setWeight(70);
    System.out.println("p1.setWeight() = "+person1.getWeight());
    }
}



58. PROGRAM 58
public class WeatherStation1
{
    public static void main (String args[]){
    WeatherData weatherData = new WeatherData();
    Display temperature = new DisplayTemperature(weatherData);
    Display humidity = new DisplayHumidity(weatherData);
    Display pressure = new DisplayPressure(weatherData);
   
    for (int i =0; i<4; i++){
        weatherData.setMeasurements((float)(80+(i*1.4)),
        (float)(65+(i*2.4)),(float)(30.4f+(i*11.2)));
       
        System.out.println("---------");
       
        if(i==1){
            temperature.setChart(new ChartWithPai());
            humidity.setChart(new ChartWithLine());
            pressure.setChart(new ChartWithBar());
        }
       
        if(i==2){
            weatherData.removeObserver((Observer)pressure);
        }
    }
}
}

public class DisplayHumidity extends Display implements Observer
{
   private float humidity = 35.00f;
   private Subject weatherData;
 
   public DisplayHumidity(Subject weatherData){
     chartBehavior = new ChartWithPai();
     this.weatherData = weatherData;
     weatherData.registerObserver(this);
    }
   
    public void update(float temperature, float humidity, float pressure){
    this.humidity = humidity;
    display();
    }
   
    public void display(){
    System.out.print("display humidity wiht "+chartBehavior.getTypeChart()+" ");
    performChart(humidity);
    }
}
public class DisplayTemperature extends Display implements Observer{
    private float temperature = 75.00f;
    private Subject weatherData;
   
    //UNTUK WEATHER STATION
    public DisplayTemperature(Subject weatherData){
        //initialise instanse variables
        chartBehavior = new ChartWithBar();
        this.weatherData = weatherData;
        weatherData.registerObserver(this);
    }
    public void update(float temperature, float humidity, float pressure){
        this.temperature = temperature;
        display();
    }
    public void display(){
        System.out.print("Display temperature with " +chartBehavior.getTypeChart()+ "");
        performChart(temperature); //UNTUK WATHER STATION
        //performChart();
    }
}

public class DisplayPressure extends Display implements Observer{
    private float pressure = 76.00f;
    private Subject weatherData;
   
    //UNTUK WEATHER STATION
    public DisplayPressure(Subject weatherData){
        //initialise instance variables
        chartBehavior = new ChartWithPai();
        this.weatherData = weatherData;
        weatherData.registerObserver(this);
    }
   
    public void update(float temperature, float humidity, float pressure){
    this.pressure = pressure;
    display();
    }
   
    public void display(){
        System.out.println("Display Temperature with" + chartBehavior.getTypeChart()+"");
        performChart(pressure); //UNTUK WEATHER STATION
    }
}

public interface Subject
{
    public void registerObserver(Observer ob);
    public void removeObserver(Observer ob);
    public void notifyObserver();
}

public interface Observer
{
   public void update(float temp, float humidity, float pressure);
}

public interface ChartBehavior
{
    public void drawChart(float value); //untuk weather station
    public String getTypeChart();
}

public abstract class Display
{
    ChartBehavior chartBehavior;
   
    public Display(){}
   
    public abstract void display();
   
    public void performChart(float value){
        chartBehavior.drawChart(value);
    }
   
    public void setChart(ChartBehavior chartBehavior){
        this.chartBehavior = chartBehavior;
    }
}

import java.util.ArrayList;
public class WeatherData implements Subject{
    private ArrayList<Observer> observers;
    private float temperature;
    private float humidity;
    private float pressure;
   
    public WeatherData(){
        observers = new ArrayList<Observer>();
    }
   
    public void registerObserver(Observer ob){
        observers.add(ob);
    }
   
    public void removeObserver(Observer ob){
        int i = observers.indexOf(ob);
        if(i>=0){
            observers.remove(i);
        }
    }
   
    public void notifyObserver(){
        for(int i =0;i<observers.size();i++)
        {
            Observer observer = (Observer)observers.get(i);
            observer.update(temperature,humidity,pressure);}
    }
   
    public void measurementsChanged(){
        notifyObserver();
    }
   
    public void setMeasurements(float temperature, float humidity, float pressure){
        this.temperature=temperature;
        this.humidity=humidity;
        this.pressure=pressure;
        measurementsChanged();
    }
}

public class ChartWithPai implements ChartBehavior
{
    private String type = "Bar";
   
    public void setTypeChart(String type){
        this.type = type;
    }
   
    public String getTypeChart(){
        return type;
    }
   
    public void drawChart(float value){
         System.out.println("level is "+value);
    }
   
}

public class ChartWithBar implements ChartBehavior
{
    private String type = "Bar";
   
    public void setTypeChart(String type){
        this.type = type;
    }
   
    public String getTypeChart(){
        return type;
    }
   
    public void drawChart(float value){
         System.out.println("level is "+value);
    }
   
}

public class ChartWithLine implements ChartBehavior
{
    private String type = "Line";
   
    public void setTypeChart(String type){
        this.type = type;
    }
   
    public String getTypeChart(){
        return type;
    }
   
    public void drawChart(float value){
         System.out.println("level is "+value);
    }
}



59. PROGRAM 59
package latihan.pkg2;
class Karyawan{
    public double id_karyawan, Jumlah_jam_kerja, Upah_jam_kerja;
    public double Gajikotor, Gajibersih;
   
    public void setID(double id_karyawan){
        this.id_karyawan = id_karyawan;
    }
   
    public double getID(){
        return id_karyawan;
    }
   
    public void setJumlahjamkerja(double jamkerja){
        Jumlah_jam_kerja = jamkerja;
    }
   
    public double getJumlahjamkerja(){
        return Jumlah_jam_kerja;
    }
   
    public void setUpahjamkerja(int upahkerja){
        Upah_jam_kerja = upahkerja;
    }
   
    public double getUpahjamkerja(){
        return Upah_jam_kerja;
    }
   
    public double hitungGajikotor(){
        if(Jumlah_jam_kerja<=40){
            Gajikotor = Jumlah_jam_kerja * Upah_jam_kerja;
        } else {
            Gajikotor = 40*Upah_jam_kerja+1.5*(Jumlah_jam_kerja - 40)*Upah_jam_kerja;
        }
        return Gajikotor;
    }
   
    public double hitungGajibersih(){
        if (Gajikotor>1000000){
            Gajibersih = Gajikotor - 5000;
        } else{
            Gajibersih = Gajikotor;
        }
        return Gajibersih;
    }
}

public class Latihan2 {
    public static void main(String[] args) {
        Karyawan anam = new Karyawan();
       
        anam.setID(13218);
        anam.setJumlahjamkerja(50);
        anam.setUpahjamkerja(40000);
       
       
        System.out.println("Nomor ID Karawan            : "+anam.getID());
        System.out.println("Jumlah Jam Kerja            : "+anam.getJumlahjamkerja());
        System.out.println("Upah kerja per jam          : "+anam.getUpahjamkerja());
        System.out.println("Jumlah Gaji Kotor           : "+anam.hitungGajikotor());
        System.out.println("Jumlah Gaji bersih          : "+anam.hitungGajibersih());
    }
}



60. PROGRAM 60
package latihan.pkg3;

class Karyawan{
    public int nomor_nik;
    public String nama;
    public int umur;
    public String alamat;
    public String jabatan;
    public int mulaikerja; //
    public double pokokGaji=3000000; //gaji perbulan
    public double totalGaji=0;
   
   
    public void setData(int nomor_nik, String nama, int umur, String alamat, String jabatan, int mulaikerja){
        this.nomor_nik = nomor_nik;
        this.nama = nama;
        this.umur = umur;
        this.alamat = alamat;
        this.jabatan = jabatan;
        this.mulaikerja = mulaikerja;
    }
   
    public int hitungmasakerja(){
        return 50-umur;
    }
   
    public int hitungTahunpensiun(){
        return mulaikerja + hitungmasakerja();
    }
   
    public double updateTotalGaji(){
        totalGaji = totalGaji +(pokokGaji*(hitungmasakerja()*12));
        return totalGaji;
    }
   
    public void dispayInfo(){
        System.out.println("Nomor NIK       : "+nomor_nik);
        System.out.println("Nama            : "+nama);
        System.out.println("Umut            : "+umur);
        System.out.println("Alamat          : "+alamat);
        System.out.println("Jabatan         : "+jabatan);
        System.out.println("Masa Kerja      : "+hitungmasakerja());
        System.out.println("Tahun Pensiun   : "+hitungTahunpensiun());
        System.out.println("Total Gaji      : "+updateTotalGaji());
    } 
}

package latihan.pkg3;
public class KaryawanTetap extends Karyawan implements hitungGajiMingguan {
    public double gajimingguan;
    public void hitungGajiMingguan(){
        gajimingguan = pokokGaji / 4;
        System.out.println("Gaji Mingguan karyawan      : "+gajimingguan);
    }
}

package latihan.pkg3;
public class KaryawanHarian extends Karyawan implements hitungGajiMingguan {
    public double gajimingguan;
    public void hitungGajiMingguan(){
        gajimingguan = pokokGaji / (4);
        System.out.println("Gaji Mingguan Karyawan Harian       : "+gajimingguan);
    }
   
   
}

package latihan.pkg3;
public interface hitungGajiMingguan  {
        public void hitungGajiMingguan();
}

package latihan.pkg3;
public class mainclass {
    public static void main(String args []){
        KaryawanTetap anam = new KaryawanTetap();
        //int nomor_nik, String nama, int umur, String alamat, String jabatan, int mulaikerja
        anam.setData(13218, "Khaerul Anam", 23, "Boyolali", "Direktur 1", 2016);
       
        System.out.println("====================================");
        anam.dispayInfo();
        anam.hitungGajiMingguan();
       
        KaryawanHarian anam2 = new KaryawanHarian();
        //int nomor_nik, String nama, int umur, String alamat, String jabatan, int mulaikerja
        anam2.setData(415353, "Arfan Salamun", 26, "Jakarta", "CEO", 2016);
       
        System.out.println(" ");
        System.out.println("====================================");
        anam2.dispayInfo();
        anam2.hitungGajiMingguan();
    }
}



61. PROGRAM 61
package soal.responsi.pkg1;

class Shape{
    void draw(){};
}

class Circle extends Shape{
    void draw(){
        System.out.println("Inside Circle :: draw() method.");
    }
}

class Rectangle extends Shape{
    void draw(){
        System.out.println("Inside Rectangle :: draw() method.");
    }
}

class Square extends Shape{
    void draw(){
        System.out.println("Inside Square :: draw() method.");
    }
}
public class SOALRESPONSI1 {
    public static void main(String[] args) {
        Shape circle = new Circle();
        circle.draw();
        Shape rectangle = new Rectangle();
        rectangle.draw();
        Shape square = new Square();
        square.draw();
    }
}



62. PROGRAM 62
package soal.responsi.pkg2;
import java.util.Scanner;

class pegawai{
    double golongan, kode_pegawai, absensi;
    double gajipokok, transport, t_transport, gajikotor, pph, gajibersih;
    String nama, jabatan;
    public pegawai(double golongan, double kode_pegawai, String nama, double absensi){
        this.golongan = golongan;
        this.kode_pegawai=kode_pegawai;
        this.nama=nama;
        this.absensi=absensi;
    }
    void tunjangantransport(){};
    void gajikotor(){};
    void PPH(){};
    void gajibersih(){};
}


class manager extends pegawai{
    public manager(double golongan, double kode_pegawai, String nama, double absensi){
        super(golongan,kode_pegawai, nama, absensi);
    };
    void tunjangantransport(){
        transport = 100000;
        t_transport = transport * absensi;
    };
    void gajikotor(){
        gajipokok = 3200000;
        gajikotor = gajipokok + t_transport;
    };
    void PPH(){
        if(gajikotor >= 2500000){
            pph = gajikotor * 2/100;
        }else{
            pph=0;
        }
    };
    void gajibersih(){
        gajibersih = gajikotor - pph;
    };
}


class supervisor extends pegawai{
    public supervisor(double golongan, double kode_pegawai, String nama, double absensi){
        super(golongan,kode_pegawai, nama, absensi);
    }
   
    void tunjangantransport(){
        transport = 75000;
        t_transport = transport * absensi;
    };
    void gajikotor(){
        gajipokok = 2750000;
        gajikotor = gajipokok + t_transport;
    };
    void PPH(){
        if(gajikotor >= 2500000){
            pph = gajikotor * 2/100;
        }else{
            pph=0;
        }
    };
    void gajibersih(){
        gajibersih = gajikotor - pph;
    };
}


class staff extends pegawai{
    public staff(double golongan, double kode_pegawai, String nama, double absensi){
        super(golongan,kode_pegawai, nama, absensi);
    }
   
    void tunjangantransport(){
        transport = 50000;
        t_transport = transport * absensi;
    };
    void gajikotor(){
        gajipokok = 2000000;
        gajikotor = gajipokok + t_transport;
    };
    void PPH(){
        if(gajikotor >= 2500000){
            pph = gajikotor * 2/100;
        }else{
            pph=0;
        }
    };
    void gajibersih(){
        gajibersih = gajikotor - pph;
    };
}


class assistenstaff extends pegawai{
    public assistenstaff(double golongan, double kode_pegawai, String nama, double absensi){
        super(golongan,kode_pegawai, nama, absensi);
    }
    void tunjangantransport(){
        transport = 100000;
        t_transport = transport * absensi;
    };
    void gajikotor(){
        gajipokok = 3200000;
        gajikotor = gajipokok + t_transport;
    };
    void PPH(){
        if(gajikotor >= 2500000){
            pph = gajikotor * 2/100;
        }else{
            pph=0;
        }
    };
    void gajibersih(){
        gajibersih = gajikotor - pph;
    };
}


public class SOALRESPONSI2 {

    public static void main(String[] args) {
        double gol, kode, absen;
        String nam,bul;
        pegawai anam;
        Scanner input = new Scanner(System.in);
        System.out.print("Masukkan golongan (1-4): ");
        gol = input.nextDouble();
        System.out.print("Masukkan kode pegawai : ");
        kode = input.nextDouble();
        System.out.print("Masukkan nama pegawai : ");
        nam = input.next();
        System.out.print("Masukkan jumlah kehadiran (1-30): ");
        absen = input.nextDouble();
       
        if (gol == 1){
            anam = new manager (gol, kode, nam, absen);
            anam.tunjangantransport();
            anam.gajikotor();
            anam.PPH();
            anam.gajibersih();
            anam.jabatan = "Manager";
            System.out.println(" ");
            System.out.println(" ");
            System.out.println("========Laporan Keuangan========");
            System.out.println("Kode pegawai : "+anam.kode_pegawai);
            System.out.println("Nama Pegawai : "+anam.nama);
            System.out.println("Golongan : "+anam.golongan);
            System.out.println("Absensi / Jumlah kehadiran = "+anam.absensi);
            System.out.println("Jabatan : "+anam.jabatan);
            System.out.println("Gaji pokok : "+anam.gajipokok);
            System.out.println("Transport/Hr : "+anam.transport);
            System.out.println("Tunjangan Transport :"+anam.t_transport);
            System.out.println("Gaji kotor : "+anam.gajikotor);
            System.out.println("PPH : "+anam.pph);
            System.out.println("Gaji bersih : "+anam.gajibersih);
        }
        else if(gol == 2){
            anam = new supervisor (gol, kode, nam, absen);
            anam.tunjangantransport();
            anam.gajikotor();
            anam.PPH();
            anam.gajibersih();
            anam.jabatan = "Supervisor";
            System.out.println(" ");
            System.out.println(" ");
            System.out.println("========Laporan Keuangan========");
            System.out.println("Kode pegawai : "+anam.kode_pegawai);
            System.out.println("Nama Pegawai : "+anam.nama);
            System.out.println("Golongan : "+anam.golongan);
            System.out.println("Absensi / Jumlah kehadiran = "+anam.absensi);
            System.out.println("Jabatan : "+anam.jabatan);
            System.out.println("Gaji pokok : "+anam.gajipokok);
            System.out.println("Transport/Hr : "+anam.transport);
            System.out.println("Tunjangan Transport :"+anam.t_transport);
            System.out.println("Gaji kotor : "+anam.gajikotor);
            System.out.println("PPH : "+anam.pph);
            System.out.println("Gaji bersih : "+anam.gajibersih);
        }
        else if (gol == 3){
            anam = new staff (gol, kode, nam, absen);
            anam.tunjangantransport();
            anam.gajikotor();
            anam.PPH();
            anam.gajibersih();
            anam.jabatan = "Staff";
            System.out.println(" ");
            System.out.println(" ");
            System.out.println("========Laporan Keuangan========");
            System.out.println("Kode pegawai : "+anam.kode_pegawai);
            System.out.println("Nama Pegawai : "+anam.nama);
            System.out.println("Golongan : "+anam.golongan);
            System.out.println("Absensi / Jumlah kehadiran = "+anam.absensi);
            System.out.println("Jabatan : "+anam.jabatan);
            System.out.println("Gaji pokok : "+anam.gajipokok);
            System.out.println("Transport/Hr : "+anam.transport);
            System.out.println("Tunjangan Transport :"+anam.t_transport);
            System.out.println("Gaji kotor : "+anam.gajikotor);
            System.out.println("PPH : "+anam.pph);
            System.out.println("Gaji bersih : "+anam.gajibersih);
        }
        else if(gol == 4){
            anam = new assistenstaff (gol, kode, nam, absen);
            anam.tunjangantransport();
            anam.gajikotor();
            anam.PPH();
            anam.gajibersih();
            anam.jabatan = "Assisten Staff";
            System.out.println(" ");
            System.out.println(" ");
            System.out.println("========Laporan Keuangan========");
            System.out.println("Kode pegawai : "+anam.kode_pegawai);
            System.out.println("Nama Pegawai : "+anam.nama);
            System.out.println("Golongan : "+anam.golongan);
            System.out.println("Absensi / Jumlah kehadiran = "+anam.absensi);
            System.out.println("Jabatan : "+anam.jabatan);
            System.out.println("Gaji pokok : "+anam.gajipokok);
            System.out.println("Transport/Hr : "+anam.transport);
            System.out.println("Tunjangan Transport :"+anam.t_transport);
            System.out.println("Gaji kotor : "+anam.gajikotor);
            System.out.println("PPH : "+anam.pph);
            System.out.println("Gaji bersih : "+anam.gajibersih);
        };
    }
   
}



63. PROGRAM 63
package manager;

import java.util.Scanner;

abstract class Manager {
    double golongan, kode_pegawai, absensi;
    double gajipokok, transport, t_transport, gajikotor, pph, gajibersih;
    String nama, jabatan;
   
    public Manager(double golongan, double kode_pegawai, String nama, double absensi){
        this.golongan = golongan;
        this.kode_pegawai=kode_pegawai;
        this.nama=nama;
        this.absensi=absensi;
    }
    void getjabatan(String jabatan){};
    void tunjangantransport(){};
    void gajikotor(){};
    void PPH(){};
    void gajibersih(){}; 
}


class LendingManager extends Manager{
    public LendingManager(double golongan, double kode_pegawai, String nama, double absensi){
        super(golongan,kode_pegawai, nama, absensi);
    };
    void getjabatan(String jabatan){
        this.jabatan = jabatan;
    };
    void tunjangantransport(){
        transport = 100000;
        t_transport = transport * absensi;
    };
    void gajikotor(){
        gajipokok = 5000000;
        gajikotor = gajipokok + t_transport;
    };
    void PPH(){
        if(gajikotor >= 2500000){
            pph = gajikotor * 2/100;
        }else{
            pph=0;
        }
    };
    void gajibersih(){
        gajibersih = gajikotor - pph;
    };
}


class FundingManager extends Manager{
    public FundingManager(double golongan, double kode_pegawai, String nama, double absensi){
        super(golongan,kode_pegawai, nama, absensi);
    }
    void getjabatan(String jabatan){
        this.jabatan = jabatan;
    };
    void tunjangantransport(){
        transport = 75000;
        t_transport = transport * absensi;
    };
    void gajikotor(){
        gajipokok = 4500000;
        gajikotor = gajipokok + t_transport;
    };
    void PPH(){
        if(gajikotor >= 2500000){
            pph = gajikotor * 2/100;
        }else{
            pph=0;
        }
    };
    void gajibersih(){
        gajibersih = gajikotor - pph;
    };
}


class OperationManager extends Manager{
    public OperationManager(double golongan, double kode_pegawai, String nama, double absensi){
        super(golongan,kode_pegawai, nama, absensi);
    }
    void getjabatan(String jabatan){
        this.jabatan = jabatan;
    };
    void tunjangantransport(){
        transport = 50000;
        t_transport = transport * absensi;
    };
    void gajikotor(){
        gajipokok = 4000000;
        gajikotor = gajipokok + t_transport;
    };
    void PPH(){
        if(gajikotor >= 2500000){
            pph = gajikotor * 2/100;
        }else{
            pph=0;
        }
    };
    void gajibersih(){
        gajibersih = gajikotor - pph;
    };
}


class KreditManager extends Manager{
    public KreditManager(double golongan, double kode_pegawai, String nama, double absensi){
        super(golongan,kode_pegawai, nama, absensi);
    }
    void getjabatan(String jabatan){
        this.jabatan = jabatan;
    };
    void tunjangantransport(){
        transport = 100000;
        t_transport = transport * absensi;
    };
    void gajikotor(){
        gajipokok = 3500000;
        gajikotor = gajipokok + t_transport;
    };
    void PPH(){
        if(gajikotor >= 2500000){
            pph = gajikotor * 2/100;
        }else{
            pph=0;
        }
    };
    void gajibersih(){
        gajibersih = gajikotor - pph;
    };
}


class ServiceManager extends Manager{
    public ServiceManager(double golongan, double kode_pegawai, String nama, double absensi){
        super(golongan,kode_pegawai, nama, absensi);
    }
    void getjabatan(String jabatan){
        this.jabatan = jabatan;
    };
    void tunjangantransport(){
        transport = 100000;
        t_transport = transport * absensi;
    };
    void gajikotor(){
        gajipokok = 3500000;
        gajikotor = gajipokok + t_transport;
    };
    void PPH(){
        if(gajikotor >= 2500000){
            pph = gajikotor * 2/100;
        }else{
            pph=0;
        }
    };
    void gajibersih(){
        gajibersih = gajikotor - pph;
    };
}


class utama{
    public static void main(String[] args) {
        double gol, kode, absen;
        String nam,bul;
        Manager anam;
        Scanner input = new Scanner(System.in);
        System.out.print("Masukkan golongan (1-5): ");
        gol = input.nextDouble();
        System.out.print("Masukkan kode pegawai : ");
        kode = input.nextDouble();
        System.out.print("Masukkan nama pegawai : ");
        nam = input.next();
        System.out.print("Masukkan jumlah kehadiran (1-30): ");
        absen = input.nextDouble();
       
        if (gol == 1){
            anam = new LendingManager (gol, kode, nam, absen);
            anam.tunjangantransport();
            anam.gajikotor();
            anam.PPH();
            anam.gajibersih();
            anam.getjabatan("Lending Manager");
            System.out.println(" ");
            System.out.println(" ");
            System.out.println("========Laporan Gaji========");
            System.out.println("Kode pegawai : "+anam.kode_pegawai);
            System.out.println("Nama Pegawai : "+anam.nama);
            System.out.println("Golongan : "+anam.golongan);
            System.out.println("Absensi / Jumlah kehadiran = "+anam.absensi);
            System.out.println("Jabatan : "+anam.jabatan);
            System.out.println("Gaji pokok : "+anam.gajipokok);
            System.out.println("Transport/Hr : "+anam.transport);
            System.out.println("Tunjangan Transport :"+anam.t_transport);
            System.out.println("Gaji kotor : "+anam.gajikotor);
            System.out.println("PPH : "+anam.pph);
            System.out.println("Gaji bersih : "+anam.gajibersih);
        }
        else if(gol == 2){
            anam = new FundingManager (gol, kode, nam, absen);
            anam.tunjangantransport();
            anam.gajikotor();
            anam.PPH();
            anam.gajibersih();
            anam.getjabatan("Funding Manager");
            System.out.println(" ");
            System.out.println(" ");
            System.out.println("========Laporan Gaji========");
            System.out.println("Kode pegawai                : "+anam.kode_pegawai);
            System.out.println("Nama Pegawai                : "+anam.nama);
            System.out.println("Golongan                    : "+anam.golongan);
            System.out.println("Absensi / Jumlah kehadiran  : "+anam.absensi);
            System.out.println("Jabatan                     : "+anam.jabatan);
            System.out.println("Gaji pokok                  : "+anam.gajipokok);
            System.out.println("Transport/Hr                : "+anam.transport);
            System.out.println("Tunjangan Transport         :"+anam.t_transport);
            System.out.println("Gaji kotor                  : "+anam.gajikotor);
            System.out.println("PPH                         : "+anam.pph);
            System.out.println("Gaji bersih                 : "+anam.gajibersih);
        }
        else if (gol == 3){
            anam = new OperationManager (gol, kode, nam, absen);
            anam.tunjangantransport();
            anam.gajikotor();
            anam.PPH();
            anam.gajibersih();
            anam.getjabatan("Operational Manager");
            System.out.println(" ");
            System.out.println(" ");
            System.out.println("========Laporan Gaji========");
            System.out.println("Kode pegawai                : "+anam.kode_pegawai);
            System.out.println("Nama Pegawai                : "+anam.nama);
            System.out.println("Golongan                    : "+anam.golongan);
            System.out.println("Absensi / Jumlah kehadiran  : "+anam.absensi);
            System.out.println("Jabatan                     : "+anam.jabatan);
            System.out.println("Gaji pokok                  : "+anam.gajipokok);
            System.out.println("Transport/Hr                : "+anam.transport);
            System.out.println("Tunjangan Transport         : "+anam.t_transport);
            System.out.println("Gaji kotor                  : "+anam.gajikotor);
            System.out.println("PPH                         : "+anam.pph);
            System.out.println("Gaji bersih                 : "+anam.gajibersih);
        }
        else if(gol == 4){
            anam = new KreditManager (gol, kode, nam, absen);
            anam.tunjangantransport();
            anam.gajikotor();
            anam.PPH();
            anam.gajibersih();
            anam.getjabatan("Kredit Manager");
            System.out.println(" ");
            System.out.println(" ");
            System.out.println("========Laporan Gaji========");
            System.out.println("Kode pegawai                : "+anam.kode_pegawai);
            System.out.println("Nama Pegawai                : "+anam.nama);
            System.out.println("Golongan                    : "+anam.golongan);
            System.out.println("Absensi / Jumlah kehadiran  : "+anam.absensi);
            System.out.println("Jabatan                     : "+anam.jabatan);
            System.out.println("Gaji pokok                  : "+anam.gajipokok);
            System.out.println("Transport/Hr                : "+anam.transport);
            System.out.println("Tunjangan Transport         : "+anam.t_transport);
            System.out.println("Gaji kotor                  : "+anam.gajikotor);
            System.out.println("PPH                         : "+anam.pph);
            System.out.println("Gaji bersih                 : "+anam.gajibersih);
        }else if(gol == 5){
            anam = new ServiceManager (gol, kode, nam, absen);
            anam.tunjangantransport();
            anam.gajikotor();
            anam.PPH();
            anam.gajibersih();
            anam.getjabatan("Service Manager");
            System.out.println(" ");
            System.out.println(" ");
            System.out.println("========Laporan Gaji========");
            System.out.println("Kode pegawai                : "+anam.kode_pegawai);
            System.out.println("Nama Pegawai                : "+anam.nama);
            System.out.println("Golongan                    : "+anam.golongan);
            System.out.println("Absensi / Jumlah kehadiran  : "+anam.absensi);
            System.out.println("Jabatan                     : "+anam.jabatan);
            System.out.println("Gaji pokok                  : "+anam.gajipokok);
            System.out.println("Transport/Hr                : "+anam.transport);
            System.out.println("Tunjangan Transport         : "+anam.t_transport);
            System.out.println("Gaji kotor                  : "+anam.gajikotor);
            System.out.println("PPH                         : "+anam.pph);
            System.out.println("Gaji bersih                 : "+anam.gajibersih);
    }else{
            System.out.println("Golongan yang anda masukkan salah : ");
            System.out.println("Golongan 1 : LendingManager");
            System.out.println("Golongan 2 : FundingManager");
            System.out.println("Golongan 3 : OperationManager");
            System.out.println("Golongan 4 : KreditManager");
            System.out.println("Golongan 4 : ServiceManager");
        }
       
}
}