INHERITANCE
Database Akademik dengan Inheritance pada BlueJ
Kali ini saya akan membuat database akademik menggunakan BlueJ dengan konsep inheritance. Berikut source code dan tampilan akhirnya. Saya membutuhkan 1 superclass (Database), 6 subclass dan 1 class sebagai parents
Code Id :
public class ID
{
private String nama;
private String alamat;
private int umur;
public ID(String name, String address, int age)
{
nama = name;
alamat = address;
umur = age;
}
public void print()
{
System.out.println("Nama :"+ nama);
System.out.println("Alamat :"+ alamat);
System.out.println("Umur :"+ umur);
}
public String getNama()
{
return nama;
}
}
code pegawai :
import java.util.ArrayList;
public class Pegawai extends ID
{
private String nid;
private ArrayList<Buku> Buku;
public Pegawai(String name, String NID, String address, int age)
{
super(name, address, age);
nid = NID;
}
public void Pinjam(Buku ABuku)
{
Buku.add(ABuku);
}
public void Pengembalian(Buku ABuku)
{
Buku.remove(ABuku);
}
public void print()
{
System.out.println("NID : "+ nid);
super.print();
for(Buku Buku : Buku)
{
System.out.println("Judul Buku : "+ Buku.getBuku());
}
}
public void printd()
{
System.out.println("NID : "+ nid);
super.print();
}
}
code database :
import java.util.ArrayList;
public class DB
{
private ArrayList<Mahasiswa> mhs;
private ArrayList<Dosen> dos;
private ArrayList<Pegawai> pgw;
public DB()
{
mhs = new ArrayList<Mahasiswa>();
dos = new ArrayList<Dosen>();
pgw = new ArrayList<Pegawai>();
}
public void addMahasiswa(Mahasiswa Mahasiswa)
{
mhs.add(Mahasiswa);
}
public void deleteMahasiswa(Mahasiswa Mahasiswa)
{
mhs.remove(Mahasiswa);
}
public void addDosen(Dosen Dosen)
{
dos.add(Dosen);
}
public void deleteDosen(Dosen Dosen)
{
dos.remove(Dosen);
}
public void addPegawai(Pegawai Pegawai)
{
pgw.add(Pegawai);
}
public void deletePegawai(Pegawai Pegawai)
{
pgw.remove(Pegawai);
}
public void listMahasiswa()
{
System.out.println(" ");
System.out.println(" List Mahasiswa ");
System.out.println(" ");
for(Mahasiswa A : mhs)
{
A.printd();
System.out.println();
}
}
public void listDosen()
{
System.out.println(" ");
System.out.println(" Dosen List ");
System.out.println(" ");
for(Dosen A : dos)
{
A.printd();
System.out.println();
}
}
public void listPegawai()
{
System.out.println(" ");
System.out.println(" Employe List");
System.out.println(" ");
for(Pegawai A : pgw)
{
A.printd();
System.out.println();
}
}
}
code kelas :
public class Kelas
{
private String Kelas;
public Kelas(String kel)
{
Kelas = kel;
}
public String getKelas()
{
return Kelas;
}
}
code MataKuliah :
public class MK
{
private int kode;
private String mata_kuliah;
private int jum_sks;
private Kelas kls;
private String kel;
private String dos;
public MK(int Kode, String Mata_Kuliah, int sks)
{
kode = Kode;
mata_kuliah = Mata_Kuliah;
jum_sks = sks;
}
public String getMK()
{
return mata_kuliah;
}
public void addKelas(Kelas AKelas)
{
kel = AKelas.getKelas();
}
public String getKls()
{
return kel;
}
public void addDosen(Dosen Dosen)
{
dos = Dosen.getDosen();
}
public String getDsn()
{
return dos;
}
public void print()
{
System.out.println("Kode : "+ kode);
System.out.println("Mata Kuliah : "+ mata_kuliah);
System.out.println("SKS : "+ jum_sks);
}
}
code mahasiswa :
import java.util.ArrayList;
public class Mahasiswa extends ID
{
private String NRP;
private ArrayList<MK> MataKuliah;
private ArrayList<Buku> Buku;
public Mahasiswa(String name, String nrp, String address, int age)
{
super(name, address, age);
NRP = nrp;
MataKuliah = new ArrayList<MK>();
Buku = new ArrayList<Buku>();
}
public void addMK(MK Mata_Kuliah)
{
MataKuliah.add(Mata_Kuliah);
}
public void dropMK(MK Mata_Kuliah)
{
MataKuliah.remove(Mata_Kuliah);
}
public void MeminjamBuku(Buku Books)
{
Buku.add(Books);
}
public void PengembalianBuku(Buku Books)
{
Buku.remove(Books);
}
public void print()
{
System.out.println("NRP :" + NRP);
super.print();
for(MK matakuliah : MataKuliah)
{
System.out.println("Mata Kuliah : "+ matakuliah.getMK());
System.out.println("Kelas : "+ matakuliah.getKls());
System.out.println("Dosen : "+ matakuliah.getDsn());
}
for(Buku ABooks : Buku)
{
System.out.println("Judul Buku : "+ ABooks.getBuku());
}
}
public void printd()
{
System.out.println("NRP : "+ NRP);
super.print();
}
}
Komentar
Posting Komentar