MEMBUAT DATABASE SEDERHANA
Database Kelas Menggunakan beberapa kelas yakni
1. Database
2. Mahasiswa
3. Dosen
4. Kelas
5. MataKuliah
6. Pegawai
7. Buku
Berikut kelas kelasnya
1. Database
import java.util.ArrayList;
public class Database
{
private ArrayList<Object> peg;
private ArrayList<Object> dos;
private ArrayList<Object> mhs;
private ArrayList<Object> kls;
private ArrayList<Object> mk;
private ArrayList<Object> bk;
public Database(){
peg= new ArrayList<Object>();
dos= new ArrayList<Object>();
mhs= new ArrayList<Object>();
kls= new ArrayList<Object>();
mk= new ArrayList<Object>();
bk= new ArrayList<Object>();
}
public void addpeg (Object objek){
peg.add(objek);
}
public void adddos (Object objek){
dos.add(objek);
}
public void addmhs (Object objek){
mhs.add(objek);
}
public void addkls (Object objek){
kls.add(objek);
}
public void addmk (Object objek){
mk.add(objek);
}
public void addbk (Object objek){
bk.add(objek);
}
public void ambil_kelas(int ind, Mahasiswa mhs){
if(ind<=kls.size()){
Kelas temp = (Kelas)kls.get(ind-1);
temp.setkuota(false);
System.out.print("Kelas ");
temp.info();
System.out.println("berhasil diambil oleh "+mhs.getnama());
}
else System.out.println("Kelas tidak ada");
}
public void pinjam_buku(int ind, Mahasiswa mhs){
if(ind<=bk.size()){
Buku temp = (Buku)bk.get(ind-1);
temp.settok(false);
System.out.print("Buku ");
temp.info();
System.out.println("berhasil dipinjam oleh "+mhs.getnama());
}
else System.out.println("Buku tidak ada");
}
public void kembalikan_buku(int ind, Mahasiswa mhs){
if(ind<=bk.size()){
Buku temp = (Buku)bk.get(ind-1);
temp.settok(true);
System.out.print("Buku ");
temp.info();
System.out.println("berhasil dikembalikan oleh "+mhs.getnama());
}
else System.out.println("Buku tidak ada");
}
public void daftar(int id){
int no = 1;
switch(id){
case 1:
for(Object cd: peg){
System.out.println(no++);
cd.info();
System.out.println();
}
break;
case 2:
for(Object cd: dos){
System.out.println(no++);
cd.info();
System.out.println();
}
break;
case 3:
for(Object cd: mhs){
System.out.println(no++);
cd.info();
System.out.println();
}
break;
case 4:
for(Object cd: mk){
System.out.println(no++);
cd.info();
System.out.println();
}
break;
case 5:
for(Object cd: kls){
System.out.println(no++);
cd.info();
System.out.println();
}
break;
case 6:
for(Object cd: bk){
System.out.println(no++);
cd.info();
System.out.println();
}
break;
}
}
}
2. Mahasiswa
public class Mahasiswa extends Orang
{
private String status;
private double ipk;
public Mahasiswa(String name, int no, String tgl, String from, String stat, double nilai){
super(name,no,tgl,from);
this.status = stat;
this.ipk = nilai;
}
public String status(){
return status;
}
public double ipk(){
return ipk;
}
public void set_ipk(double nilai){
this.ipk=nilai;
}
public void info(){
super.info();
System.out.println(this.status()+" IPK: "+this.ipk());
}
}
3. Dosen
public class Dosen extends Orang
{
private String jabatan;
private MataKuliah matkul;
public Dosen(String name, int no, String tgl, String from, String jabat, MataKuliah mk){
super(name,no,tgl,from);
this.jabatan = jabat;
this.matkul = mk;
}
public String jabatan(){
return jabatan;
}
public String matkul(){
return matkul.getnama();
}
public MataKuliah getmatkul(){
return matkul;
}
public void info(){
super.info();
System.out.println("Jabatan: "+this.jabatan()+" Matkul:"+this.matkul());
}
}
4. Matakuliah
public class MataKuliah extends Object
{
private String deskripsi;
private int sks;
public MataKuliah(String name, int no, String des,int Sks){
super(no,name);
this.deskripsi = des;
this.sks = Sks;
}
public String getdeskripsi(){
return deskripsi;
}
public int getsks(){
return sks;
}
public void info(){
super.info();
System.out.println(this.getsks()+" sks, "+this.getdeskripsi());
}
}
5. Buku
public class Buku extends Object
{
private String penulis;
private int stok;
public Buku(String name, int no, String author,int banyak){
super(no,name);
this.penulis = author;
this.stok = banyak;
}
public String getpenulis(){
return penulis;
}
public int getstok(){
return stok;
}
public void settok(boolean tambah){
if(tambah) stok+=1;
else stok-=1;
}
public void info(){
super.info();
System.out.println("Penulis: "+this.getpenulis()+" Stok:"+this.getstok());
}
}
6. Kelas
public class Kelas extends Object
{
private Dosen dosen;
private int kuota;
public Kelas(String name, int no, Dosen dos, int qt){
super(no,name);
this.dosen = dos;
this.kuota = qt;
}
public String dosen(){
return dosen.getnama();
}
public Dosen getdosen(){
return dosen;
}
public int getkuota(){
return kuota;
}
public void setkuota(boolean tambah){
if(tambah) kuota+=1;
else kuota-=1;
}
public void info(){
System.out.println("Dosen: "+this.dosen());
System.out.println("Kelas: "+this.getnama()+" kuota:"+this.getkuota());
}
}
7. Pegawai
public class Pegawai extends Orang
{
private String bagian;
public Pegawai(String name, int no, String tgl, String from, String bag){
super(name,no,tgl,from);
this.bagian = bag;
}
public String bagian(){
return bagian;
}
public void info(){
super.info();
System.out.println("Bagian: "+this.bagian());
}
}
Tidak ada komentar:
Posting Komentar