Untuk membuat Database Akademik diperlukan 8 Class:
1. Orang
2. Pegawai
3. Mahasiswa
4. Dosen
5. Database
6. Buku
7. Matkul
8. Kelas
Tampilan
Source Code
Orang
/**
* Write a description of class Orang here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Orang{
private String mnama, mjkel, malamat;
private int mumur;
public Orang(String nama, String jenis_kelamin, int umur, String alamat){
mnama = nama;
mjkel = jenis_kelamin;
mumur = umur;
malamat = alamat;
}
public void display(){
System.out.println("Nama :" +mnama);
System.out.println("Jenis Kelamin :" +mjkel);
System.out.println("Umur :" +mumur);
System.out.println("Alamat :" +malamat);
}
public String getNama(){
return mnama;
}
}
Pegawai
/**
* Write a description of class a here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.ArrayList;
public class Pegawai extends Orang
{
private String mNIP;
private ArrayList<Buku> mbuku;
public Pegawai(String nama, String jenis_kelamin, int umur, String alamat, String nip)
{
super(nama, jenis_kelamin, umur, alamat);
mNIP = nip;
mbuku = new ArrayList<Buku>();
}
public void pinjambuku(Buku bk)
{
mbuku.add(bk);
}
public void kembalikanBuku(Buku bk)
{
mbuku.remove(bk);
}
public void print()
{
super.display();
System.out.println("NIP :" +mNIP);
for(Buku buku : mbuku)
{
System.out.println("Judul buku yang dipinjam :" +buku.getJudul());
}
}
public void printList()
{
super.display();
System.out.println("NIP :" +mNIP);
}
}
Mahasiswa
/**
* Write a description of class Mahasiswa here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.ArrayList;
public class Mahasiswa extends Orang
{
private String mNRP;
private ArrayList<Matkul> mmatkul;
private ArrayList<Buku> mbuku;
public Mahasiswa(String nama, String jenis_kelamin, int umur, String alamat, String nrp)
{
super(nama, jenis_kelamin, umur, alamat);
mNRP = nrp;
mmatkul = new ArrayList<Matkul>();
mbuku = new ArrayList<Buku>();
}
public String getNRP()
{
return mNRP;
}
public void addMatkul(Matkul matkul)
{
mmatkul.add(matkul);
}
public void dropMatkul(Matkul matkul)
{
mmatkul.remove(matkul);
}
public void pinjamBuku(Buku bk)
{
mbuku.add(bk);
}
public void kembalikanBuku(Buku bk)
{
mbuku.remove(bk);
}
public void print()
{
super.display();
System.out.println("NRP :" +mNRP);
for(Matkul matakuliah : mmatkul)
{
System.out.println("Mata Kuliah :" +matakuliah.getMatkul());
System.out.println("Kelas :" +matakuliah.getKls());
System.out.println("Dosen :" +matakuliah.getNamaDosen());
}
for(Buku buku : mbuku)
{
System.out.println("Judul buku yang dipinjam :" +buku.getJudul());
}
}
public void printList()
{
super.display();
System.out.println("NRP :" +mNRP);
}
}
Dosen
/**
* Write a description of class Doe here.
*
* @author (your name)
* @version (a version number or a date)
*/
/**
import java.util.ArrayList;
public class Dosen extends Orang
{
private String mNIDN;
private ArrayList<Buku> mbuku;
public Dosen(String nama, String jenis_kelamin, int umur, String alamat, String nidn)
{
super(nama, jenis_kelamin, umur, alamat);
mNIDN = nidn;
mbuku = new ArrayList<Buku>();
}
public void print()
{
super.display();
System.out.println("NIDN :" +mNIDN);
for(Buku buku : mbuku)
{
System.out.println("Judul buku yang dipinjam :" +buku.getJudul());
}
}
public String getDosen()
{
return super.getNama();
}
public void pinjambuku(Buku bk)
{
mbuku.add(bk);
}
public void kembalikanBuku(Buku bk)
{
mbuku.remove(bk);
}
public void printList()
{
super.display();
System.out.println("NID :" +mNIDN);
}
}
Database
/**
* Write a description of class a here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.ArrayList;
public class Database
{
private ArrayList<Mahasiswa> mmahasiswa;
private ArrayList<Dosen> mdosen;
private ArrayList<Pegawai> mpegawai;
public Database()
{
mmahasiswa = new ArrayList<Mahasiswa>();
mdosen = new ArrayList<Dosen>();
mpegawai = new ArrayList<Pegawai>();
}
public void addMahasiswa(Mahasiswa mhs)
{
mmahasiswa.add(mhs);
}
public void addDosen(Dosen dsn)
{
mdosen.add(dsn);
}
public void addPegawai(Pegawai pgw)
{
mpegawai.add(pgw);
}
public void listMahasiswa()
{
for(Mahasiswa mahasiswa : mmahasiswa)
{
mahasiswa.printList();
System.out.println();
}
}
public void listDosen()
{
for(Dosen dosen : mdosen)
{
dosen.printList();
System.out.println();
}
}
public void listPegawai()
{
for(Pegawai pegawai : mpegawai)
{
pegawai.printList();
System.out.println();
}
}
public void delMahasiswa(Mahasiswa mhs)
{
mmahasiswa.remove(mhs);
}
public void delPegawai(Pegawai pgw)
{
mpegawai.remove(pgw);
}
public void delMahasiswa(Dosen dsn)
{
mdosen.remove(dsn);
}
}
Buku
/**
* Write a description of class a here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Buku
{
private String mpenulis;
private String mjudul;
public Buku(String judul, String penulis)
{
mjudul=judul;
mpenulis=penulis;
}
public String getJudul()
{
return mjudul;
}
}
Matkul
/**
* Write a description of class a here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Matkul
{
private int mkode, mjumlah_sks;
private String mmatkul, mkelas, mdosen;
public Matkul(int kd, String mk, int sks)
{
mkode = kd;
mmatkul = mk;
mjumlah_sks = sks;
}
public void addDosen(Dosen dsn)
{
mdosen=dsn.getDosen();
}
public String getNamaDosen()
{
return mdosen;
}
public String getMatkul()
{
return mmatkul;
}
public void addKelas(Kelas kls)
{
mkelas = kls.getKelas();
}
public String getKls()
{
return mkelas;
}
public void print()
{
System.out.println("Kode :" +mkode);
System.out.println("Mata Kuliah :" +mmatkul);
System.out.println("SKS :" +mjumlah_sks);
}
}
Kelas
/**
* Write a description of class a here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Kelas
{
private String mkelas;
public Kelas(String kelas)
{
mkelas=kelas;
}
public String getKelas()
{
return mkelas;
}
}
Comments
Post a Comment