Tugas - PBO - B
1. Person
2. Mahasiswa
3. Dosen
4. Book
5. Pegawai
6. Kelas
Dibawah ini adalah source code database sistem akademik sederhana :
1. Person
/**
* Write a description of class Item here.
*
* @author Chris Angga
* @version 1.0 (26 November 2018)
*/
public class Person{
private String name_x, gender_x, address_x;
private int old_x;
public Person(String name, String gender, int old, String address){
name_x = name;
gender_x = gender;
old_x = old;
address_x = address;
}
public void display(){
System.out.println("Nama :" +name_x);
System.out.println("Jenis Kelamin :" +gender_x);
System.out.println("Umur :" +old_x);
System.out.println("Alamat :" +address_x);
}
public String getName(){
return name_x;
}
}
2. Mahasiswa /**
* Write a description of class Mahasiswa here.
*
* @author Chris Angga
* @version 1.0 (26 November 2018)
*/
import java.util.ArrayList;
public class Mahasiswa extends Person
{
private String NRP_x;
private ArrayList<Matkul> matkul_x;
private ArrayList<Book> book_x;
public Mahasiswa(String name, String gender, int old, String address, String nrp)
{
super(name, gender, old, address);
NRP_x = nrp;
matkul_x = new ArrayList<Matkul>();
book_x = new ArrayList<Book>();
}
public String getNRP()
{
return NRP_x;
}
public void addMatkul(Matkul matkul)
{
matkul_x.add(matkul);
}
public void dropMatkul(Matkul matkul)
{
matkul_x.remove(matkul);
}
public void pinjamBuku(Book bk)
{
book_x.add(bk);
}
public void kembalikanBuku(Book bk)
{
book_x.remove(bk);
}
public void print()
{
super.display();
System.out.println("NRP :" +NRP_x);
for(Matkul matakuliah : matkul_x)
{
System.out.println("Mata Kuliah :" +matakuliah.getMatkul());
System.out.println("Kelas :" +matakuliah.getKls());
System.out.println("Dosen :" +matakuliah.getNamaDosen());
}
for(Book book : book_x)
{
System.out.println("Judul buku yang dipinjam :" +book.getJudul());
}
}
public void printList()
{
super.display();
System.out.println("NRP :" +NRP_x);
}
}
3. Dosen
/**
* Write a description of class Lecture here.
*
* @author Chris Angga
* @version 1.0 (26 November 2018)
*/
import java.util.ArrayList;
public class Dosen extends Person
{
private String NIDN_x;
private ArrayList<Book> book_x;
public Dosen(String name, String gender, int old, String address, String nidn)
{
super(name, gender, old, address);
NIDN_x = nidn;
book_x = new ArrayList<Book>();
}
public void print()
{
super.display();
System.out.println("NIDN :" +NIDN_x);
for(Book book : book_x)
{
System.out.println("Judul buku yang dipinjam :" +book.getJudul());
}
}
public String getDosen()
{
return super.getName();
}
public void pinjambuku(Book bk)
{
book_x.add(bk);
}
public void kembalikanBuku(Book bk)
{
book_x.remove(bk);
}
public void printList()
{
super.display();
System.out.println("NID :" +NIDN_x);
}
}
4. Book
/**
* Write a description of class Book here.
*
* @author Chris Angga
* @version 1.0 (26 November 2018)
*/
public class Book
{
private String penulis_x;
private String judul_x;
public Book(String judul, String penulis)
{
judul_x=judul;
penulis_x=penulis;
}
public String getJudul()
{
return judul_x;
}
}
5. Pegawai
/**
* Write a description of class employee here.
*
* @author Chris Angga
* @version 1.0 (26 November 2018)
*/
import java.util.ArrayList;
public class Pegawai extends Person
{
private String NIP_x;
private ArrayList<Book> book_x;
public Pegawai(String name, String gender, int old, String address, String nip)
{
super(name, gender, old, address);
NIP_x = nip;
book_x = new ArrayList<Book>();
}
public void pinjambuku(Book bk)
{
book_x.add(bk);
}
public void kembalikanBuku(Book bk)
{
book_x.remove(bk);
}
public void print()
{
super.display();
System.out.println("NIP :" +NIP_x);
for(Book book : book_x)
{
System.out.println("Judul buku yang dipinjam :" +book.getJudul());
}
}
public void printList()
{
super.display();
System.out.println("NIP :" +NIP_x);
}
}
6. Kelas
/**
* Write a description of class Kelas here.
*
* @author Chris Angga
* @version 1.0 (26 November 2018)
*/
public class Kelas
{
private String kelas_x;
public Kelas(String kelas)
{
kelas_x=kelas;
}
public String getKelas()
{
return kelas_x;
}
}
7. Matkul
/**
* Write a description of class Matkul here.
*
* @author Gede
* @version 1.0 (22 November 2018)
*/
public class Matkul
{
private int kode_x, jumlah_sks_x;
private String matkul_x, kelas_x, dosen_x;
public Matkul(int kd, String mk, int sks)
{
kode_x = kd;
matkul_x = mk;
jumlah_sks_x = sks;
}
public void addDosen(Dosen dsn)
{
dosen_x=dsn.getDosen();
}
public String getNamaDosen()
{
return dosen_x;
}
public String getMatkul()
{
return matkul_x;
}
public void addKelas(Kelas kls)
{
kelas_x = kls.getKelas();
}
public String getKls()
{
return kelas_x;
}
public void print()
{
System.out.println("Kode :" +kode_x);
System.out.println("Mata Kuliah :" +matkul_x);
System.out.println("SKS :" +jumlah_sks_x);
}
}
Class Program
Contoh Run Program
Tidak ada komentar:
Posting Komentar