tugas Paktikum PBO inheriten

Langkah petama buatlah sebuah kelas induk 

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package praktikum2;

/**
 *
 * @author anik
 */
public class indukFilmMusik {

    String judul;
    int stok;
    String publiser;
    String kategori;

    public indukFilmMusik(String judul, String publiser, String kategori, int stok) {

        this.judul = judul;
        this.publiser = publiser;
        this.kategori = kategori;
        this.stok = stok;
        if (kategori == ("SU")) {
            this.kategori = "Semua umur";
        } else if (kategori == ("D")) {
            this.kategori = "Dewasa";
        } else if (kategori == ("R")) {
            this.kategori = "Remaja";
        } else if (kategori == ("A")) {
            this.kategori = "Anak-anak";
        } else if (kategori == ("C")) {
            this.kategori = "Clasik";
        } else if (kategori == ("J")) {
            this.kategori = "Jazz";
        } else if (kategori == ("Pp")) {
            this.kategori = "Pop";
        } else if (kategori == "O") {
            this.kategori = "Other";
        }

    }

    public String toString() {
        return ("Judul : " + judul + "\nPubliser : " + publiser + "\nKategori : " + kategori + "Stok" + stok);
    }
}


Kemudian buat kelas anak (Child)
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package praktikum2;

/**
 *
 * @author anik
 */
public class CdFilem extends indukFilmMusik {

    private String pemain;
    private String Sutradara;

    public CdFilem(String judul, String pemain, String Sutradara, String publiser, String kategori, int stok) {
        super(judul,publiser,kategori,stok);
        this.Sutradara = Sutradara;
        this.pemain = pemain;
    }

    public String toString() {
        return ("\nJudul Filem : " + judul +"\nPemain : "+pemain+ "\nSutradara : " +Sutradara + "\nPubliser: " + publiser + "\nKategori : " + kategori+"\nStok : "+stok);
       
    }
}


membuat kelas anak yang kedua (child)

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package praktikum2;

/**
 *
 * @author anik
 */
public class CdMusik extends indukFilmMusik{
    private String penyanyi;
    private String tophits;
    private String produser;
   
    public CdMusik(String judul, String penyanyi, String produser, String publiser, String topHits, String kategori,int stok) {
        super(judul,publiser,kategori,stok);
        this.penyanyi = penyanyi;
        this.tophits = topHits;
        this.produser=produser;
}
     public String toString() {
        return ("\nJudul Musik : " + judul + "\nPenyanyi : " +penyanyi+"\nProduser: "+produser+ "\nPubliser: "
                + publiser +"\nTop Hits : "+tophits+ "\nKategori : " + kategori+"\nStok : "+stok);
}

}

class entri data
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package praktikum2;

/**
 *
 * @author anik
 */
public class entru {
    public static void main(String[] args) {
       
        CdFilem xx = new CdFilem("Laskar pelangi", "ikal", "Andra Herata", "Surya Citra Picture", "O", 10);
        CdMusik zz = new CdMusik("Sendiri", "Serina", "Mp3 Musik", "Dian", "Sendiri", "J", 7);
        System.out.println(xx.toString());
        System.out.println(zz.toString());
       
       
    }
   
}

membuat class pemanggi data
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package praktikum2;

/**
 *
 * @author anik
 */
import javax.swing.*;

public class Panggil {

    public static void main(String[] args) {
        int pilih = Integer.parseInt(JOptionPane.showInputDialog(null, "pilih kategori CD:\n1. Musik\n2. filem"));
        if (pilih == 1) {
            String judulM = JOptionPane.showInputDialog(null, "Masukkan Judul : ");
            String penyanyi = JOptionPane.showInputDialog(null, "Masukkan Nama Penyanyi");
            String produserM = JOptionPane.showInputDialog(null, "Masukkan Nama Produser");
            String publiserM = JOptionPane.showInputDialog(null, "Masukkan Publiser : ");
            String topHits = JOptionPane.showInputDialog(null, "Masukkan Top Hits ");
            String kategoriM = JOptionPane.showInputDialog(null, "Masukkan kategori : ");
            String kt = null;
            if (kategoriM.equals("C")) {
                kt = "Clasik";
            } else if (kategoriM.equals("J")) {
                kt = "Jazz";
            } else if (kategoriM.equals("P")) {
                kt = "Pop";
            } else if (kategoriM.equals("R")) {
                kt = "Rock";
            } else if (kategoriM.equals("O")) {
                kt = "Other";
            }

            int stokM = Integer.parseInt(JOptionPane.showInputDialog(null, "Masukkan Stok : "));
            CdMusik zz = new CdMusik(judulM, penyanyi, produserM, publiserM, topHits, kt, stokM);
            System.out.println(zz.toString());
        } else if (pilih == 2) {
            String judulF = JOptionPane.showInputDialog(null, "Masukkan Judul : ");
            String pemainF = JOptionPane.showInputDialog(null, "Masukkan Nama Pemain : ");
            String sutradaraF = JOptionPane.showInputDialog(null, "Masukkan Nama Sutradara : ");
            String publiserF = JOptionPane.showInputDialog(null, "Masukkan Publiser : ");
            String kategoriF = JOptionPane.showInputDialog(null, "Masukkan kategori : ");
            String ketegori = null;
            if (kategoriF.equals("SU")) {
                ketegori = "Semua Umur";
            } else if (kategoriF.equals("D")) {
                ketegori = "Dewasa";
            } else if (kategoriF.equals("R")) {
                ketegori = "Remaja";
            } else if (kategoriF.equals("A")) {
                ketegori = "Anak-Anak";
            }
            int stokM = Integer.parseInt(JOptionPane.showInputDialog(null, "Masukkan Stok : "));
            CdFilem xx = new CdFilem(judulF, pemainF, sutradaraF, publiserF, ketegori, stokM);
            System.out.println(xx.toString());
        }
    }
}


Comments

Popular posts from this blog

Pengalaman KRS an yang pertama

30 Menit Sesi Akhir

Memasukkan Gambar Pada Eclipse