public class Driver{
public static void main(String[]args){
KHS k = new KHS(2013,1);
Mahasiswa mhs = new Mahasiswa("Arifin","613120056");
Teori t1= new Teori("PBO",3,100,100,100);
Teori t2= new Teori("BASDAT",3,100,100,100);
Teori t3= new Teori("MULDAS",3,100,100,100);
Praktikum p1= new Praktikum("Prak MULDAS",3,100);
Praktikum p2= new Praktikum("Prak PBO",3,100);
k.addMahasiswa(mhs);
k.addKuliah(t1);
k.addKuliah(t2);
k.addKuliah(t3);
k.addKuliah(p1);
k.addKuliah(p2);
k.displayKHS();
}
}
public class Teori extends Kuliah{
protected int tugas;
protected int uas;
protected int uts;
public Teori(String n, int s, int t, int uts, int uas){
super(n,s);
this.tugas = t;
this.uts = uts;
this.uas = uas;
}
public char getHuruf(){
int total = this.uts+this.uas+this.tugas;
if(total>=80){
return 'A';
}
else if(total>70){
return 'B';
}
else if(total>60){
return 'C';
}
else if(total>50){
return 'D';
}
else{
return 'E';
}
}
}
public class KHS{
private int tahun;
private int semester;
private Mahasiswa m;
private Kuliah[] k = new Kuliah[10];
private int jmlKuliah=0;
public KHS(int t, int s){
this.tahun = t;
this.semester = s;
}
public void addKuliah(Kuliah k){
if(k instanceof Praktikum){
Kuliah p = (Praktikum) k;
this.k[jmlKuliah] = p;
}
else{
Kuliah t= (Teori) k;
this.k[jmlKuliah] = t;
}
jmlKuliah++;
}
public void addMahasiswa(Mahasiswa m){
this.m = m;
}
public void displayKHS(){
System.out.println("Nama: "+m.getMhs());
System.out.println("Nim: "+m.getNim());
System.out.println("Tahun: "+this.tahun);
if(this.semester%2==0){
System.out.println("Genap");
}
else{
System.out.println("Ganjil");
}
for(int i =0 ; i<jmlKuliah; i++){
if(k[i] instanceof Praktikum){
Praktikum c = (Praktikum) k[i];
System.out.println(c.getNamaMK()+": "+c.getNilai() + "("+c.getSKS()+" SKS)");
}
else{
Teori c = (Teori) k[i];
System.out.println(c.getNamaMK()+": "+c.getHuruf() + "("+c.getSKS()+" SKS)");
}
}
}
}
public class Kuliah{
protected String namaMK;
protected int sks;
public Kuliah(String n, int sks){
this.namaMK=n;
this.sks = sks;
}
public String getNamaMK(){
return this.namaMK;
}
public int getSKS(){
return this.sks;
}
public void getDeskripsi(){
System.out.println("Nama Mata Kuliah: "+this.namaMK);
System.out.println("Jumlah SKS Mata Kuliah: "+this.sks);
}
}
public class Mahasiswa{
private String nim;
private String namaMhs;
public Mahasiswa(String na, String ni){
this.namaMhs = na;
this.nim = ni;
}
public String getNim(){
return this.nim;
}
public String getMhs(){
return this.namaMhs;
}
}
public class Praktikum extends Kuliah{
protected int nilai;
public Praktikum(String n, int s, int ni){
super(n,s);
this.nilai = ni;
}
@Override
public void getDeskripsi(){
super.getDeskripsi();
System.out.println("Nilai Mata Kuliah: "+this.nilai);
}
public int getNilai(){
return this.nilai;
}
}
0 komentar:
Post a Comment