Tugas kali ini adalah membuat simulasi integra menggunakan Java. Program ini hanya dapat sebatas menyimpan dan menampilkan data saja.
Berikut class-class yang saya gunakan,
Mahasiswa:
Matkul:
Database:
Pegawai:
Dosen:
Civitas:
Buku:
Kelas:
Hasilnya,
Berikut class-class yang saya gunakan,
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 Civitas
{
private String nrp;
private ArrayList<Matkul> mk;
private ArrayList<Buku> buku;
public Mahasiswa(String Nama, int Umur, String TTL, String Alamat, String NRP){
super(Nama,Umur,TTL,Alamat);
nrp = NRP;
mk = new ArrayList<Matkul>();
buku = new ArrayList<Buku>();
}
public String getNRP(){
return nrp;
}
public void addMK(Matkul matkul){
mk.add(matkul);
}
public void dropMK(Matkul matkul){
mk.remove(matkul);
}
public void pinjamBuku(Buku book){
buku.add(book);
}
public void pengembalianBuku(Buku book){
buku.remove(book);
}
public void print(){
System.out.println("NRP: " + nrp);
super.display();
for(Matkul MK : mk){
System.out.println("Mata Kuliah: " + MK.getMK());
}
}
public void prnt()
{
System.out.println("NRP :" +nrp);
super.display();
}
}
Matkul:
/**
* Write a description of class Matkul here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Matkul
{
private int kode;
private String mata_kuliah;
private int jum_sks;
private String kl;
private String dosen;
public Matkul(int kd,String mk, int sks)
{
kode = kd;
mata_kuliah = mk;
jum_sks = sks;
}
public void addDosen(Dosen dsn)
{
dosen=dsn.getDosen();
}
public String getNamaDosen()
{
return dosen;
}
public String getMK()
{
return mata_kuliah;
}
public void addKelas(Kelas kls)
{
kl=kls.getKelas();
}
public String getKls()
{
return kl;
}
public void print()
{
System.out.println("Kode :" +kode);
System.out.println("Mata Kuliah :" +mata_kuliah);
System.out.println("Jumlah SKS :" +jum_sks);
}
}
Database:
/**
* Write a description of class Database here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.ArrayList;
public class Database
{
private ArrayList<Mahasiswa> mahasiswa;
private ArrayList<Dosen> dosen;
private ArrayList<Pegawai> pegawai;
public Database(){
mahasiswa = new ArrayList<Mahasiswa>();
dosen = new ArrayList<Dosen>();
pegawai = new ArrayList<Pegawai>();
}
public void addMahasiswa(Mahasiswa Themhs)
{
mahasiswa.add(Themhs);
}
public void addDosen(Dosen dsn)
{
dosen.add(dsn);
}
public void addPegawai(Pegawai pgw)
{
pegawai.add(pgw);
}
public void listMahasiswa()
{
for(Mahasiswa mhs : mahasiswa)
{
mhs.prnt();
System.out.println();
}
}
public void listDosen()
{
for(Dosen dsn : dosen)
{
dsn.prnt();
System.out.println();
}
}
public void listPegawai()
{
for(Pegawai pgw : pegawai)
{
pgw.prnt();
System.out.println();
}
}
public void delMahasiswa(Mahasiswa Themhs)
{
mahasiswa.remove(Themhs);
}
public void delPegawai(Pegawai pgw)
{
pegawai.remove(pgw);
}
public void delMahasiswa(Dosen dsn)
{
dosen.remove(dsn);
}
}
Pegawai:
/**
* Write a description of class Pegawai here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.ArrayList;
public class Pegawai extends Civitas
{
private String NIP;
private ArrayList<Buku> buku;
public Pegawai(String Nama, int Umur, String TTL, String Alamat, String nip)
{
super(Nama,Umur,TTL,Alamat);
NIP = nip;
buku = new ArrayList<Buku>();
}
public void minjamBuku(Buku book)
{
buku.add(book);
}
public void kembalikanBuku(Buku book)
{
buku.remove(book);
}
public void print()
{
super.display();
System.out.println("NIP :" +NIP);
for(Buku bukuu : buku)
{
System.out.println("Buku yang dipinjam :" +bukuu.getJudul());
}
}
public void prnt()
{
super.display();
System.out.println("NIP :" +NIP);
}
}
Dosen:
/**
* Write a description of class Dosen here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.ArrayList;
public class Dosen extends Civitas
{
private String nid;
private ArrayList<Buku> buku;
public Dosen(String Nama, int Umur, String TTL, String Alamat, String NID){
super(Nama,Umur,TTL,Alamat);
nid = NID;
buku = new ArrayList<Buku>();
}
public void print(){
System.out.println("NID: " + nid);
super.display();
for(Buku bukuu : buku){
System.out.println("Buku yang dipinjam: " + bukuu.getJudul());
}
}
public void prnt()
{
System.out.println("NID :" +nid);
super.display();
}
public String getDosen(){
return super.getNama();
}
public void pinjamBuku(Buku book){
buku.add(book);
}
public void pengembalianBuku(Buku book){
buku.remove(book);
}
}
Civitas:
/**
* Write a description of class Civitas here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Civitas
{
private String nama;
private int umur;
private String ttl; //tempat tanggal lahir
private String alamat;
public Civitas(String Nama, int Umur, String TTL, String Alamat){
nama = Nama;
umur = Umur;
ttl = TTL;
alamat = Alamat;
}
public void display(){
System.out.println("Nama: " + nama);
System.out.println("Umur: " + umur);
System.out.println("Tempat, Tanggal Lahir: " + ttl);
System.out.println("Alamat: " + alamat);
}
public String getNama(){
return nama;
}
}
Buku:
/**
* Write a description of class Buku here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Buku
{
private String judul;
private String penulis;
public Buku(String Judul, String Penulis){
judul = Judul;
penulis = Penulis;
}
public String getJudul(){
return judul;
}
}
Kelas:
/**
* Write a description of class Kelas here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Kelas
{
private String kelas;
public Kelas(String Kelas){
kelas = Kelas;
}
public String getKelas(){
return kelas;
}
}
Hasilnya,
Komentar
Posting Komentar