public class Driver{
public static void main(String[]args){
Mahasiswa m1 = new Mahasiswa("Bejo","613120046",100,100,100);
Mahasiswa m2 = new Mahasiswa("Slamet","613120015",100,100,100);
Mahasiswa m3 = new Mahasiswa("Arifin","613120056",100,100,100);
Kelas k=new Kelas("integer","PBO");
k.addMahasiswa(m1);
k.addMahasiswa(m2);
k.addMahasiswa(m3);
k.cariMahasiswa("Arifin");
System.out.println();
k.displayDaftarMahasiswa();
}
}
public class Kelas{
private String namaKelas;
private String namaMK;
private int jumMahasiswa;
private Mahasiswa[] mhs = new Mahasiswa[50];
public Kelas(String nk, String nmk){
this.namaKelas=nk;
this.namaMK=nmk;
}
public void setNamaKelas(String n){this.namaKelas=n;}
public void setNamaMK(String n){this.namaMK=n;}
public String getNamaKelas(){return this.namaKelas;}
public String getNamaMK(){return this.namaMK;}
public void addMahasiswa(Mahasiswa m){
this.mhs[jumMahasiswa]=m;
jumMahasiswa++;
}
public void cariMahasiswa(String nama){
for(int i=0;i<jumMahasiswa; i++){
if(this.mhs[i].getNama().equals(nama)){
this.mhs[i].displayMhs();
}
}
}
public void displayDaftarMahasiswa(){
for(int i=0;i<jumMahasiswa; i++){
this.mhs[i].displayMhs();
}
}
}
public class Mahasiswa{
private String nama;
private String nim;
private Nilai n = new Nilai();
public Mahasiswa(String nama, String nim){
this.nama=nama;
this.nim=nim;
}
public Mahasiswa(String nama, String nim, int uas, int uts, int tugas){
this.nama=nama;
this.nim=nim;
n.uas=uas;
n.uts=uts;
n.tugas=tugas;
}
public void setNama(String nama){
this.nama = nama;
}
public void setNim(String nim){
this.nim = nim;
}
public Nilai getNilai(){return n;}
public String getNama(){return this.nama;}
public String getNim(){return this.nim;}
public void displayMhs(){
System.out.println("Nama: "+this.nama);
System.out.println("Nim: "+this.nim);
n.displayNilai();
}
private class Nilai{
private int uas,uts,tugas;
private double total;
public Nilai(){}
public Nilai(int uas, int uts, int tugas){
this.uas=uas;
this.uts=uts;
this.tugas=tugas;
}
public void setUts(int u){
this.uts = u;
}
public void setUas(int u){
this.uas = u;
}
public void setTugas(int u){
this.tugas = u;
}
public double getTotal(){
this.total = (0.3*this.tugas)+(0.3*this.uts)+(0.4*this.uas);
return this.total;
}
public int getUts(){return this.uts;}
public int getUas(){return this.uas;}
public int getTugas(){return this.tugas;}
public void displayNilai(){
System.out.println("Nilai Tugas: "+this.tugas);
System.out.println("Nilai UTS: "+this.uts);
System.out.println("Nilai UAS: "+this.uas);
System.out.println("Nilai Total: "+this.total);
}
}
}
0 komentar:
Post a Comment