public class cProdi {
private String kodeProdi;
private String namaProdi;
private String akreditasi;
private cMhs [] mhs;
private int jmhs, maksmhs=10;
cProdi(){
kodeProdi="XYZ";
namaProdi="ABC";
akreditasi="N/A";
//asumsi dibatasi 10 org mhs saja dulu
mhs=new cMhs[10];
jmhs=0;
System.out.println("Object Prodi dibuat...");
cProdi(String kd, String nm, String ak){
kodeProdi=kd;
namaProdi=nm;
akreditasi=ak;
//asumsi dibatasi 10 org mhs saja dulu
mhs=new cMhs[10];
jmhs=0;
System.out.println("Object Prodi dibuat...");
}
public void setMhs(cMhs m){
mhs[jmhs]=m;
}
public cMhs[] getMhs(){
return mhs;
}
public int getJMhs(){
return jmhs;
}
public void addMhs(cMhs m){
if(jmhs<maksmhs){
setMhs(m);
jmhs++;
System.out.println("Tambah Mhs Sukses...");
}
else{
System.out.println("Mhs Kelebihan!");
}
}
public void deleteMhs(String kd){
for (int i = 0; i < jmhs; i++) {
if(kd.equalsIgnoreCase(mhs[i].getNPM())){
mhs[i]=null;
//majukan isi array mhs belakangnya
//untuk mengisi elemen yg dihapus
for (int j = i; j < jmhs; j++) {
if(j==jmhs-1)
mhs[j]=null;
else
mhs[j]=mhs[j+1];
}
jmhs--;
System.out.println("Hapus Mhs Sukses...");
break;
}
}
}
public void setKodeProdi(String k){
kodeProdi=k;
}
public void setNamaProdi(String k){
namaProdi=k;
}
public void setAkreditasi(String k){
akreditasi=k;
}
public String getNamaProdi(){
return namaProdi;
}
public String getAkreditasi(){
return akreditasi;
}
public String getKodeProdi(){
return kodeProdi;
}
public String ToString(){
return kodeProdi+" "+namaProdi+" "+akreditasi;
}
}
/*satu object KRS berisi satu object mhs
dan beberapa object mata kuliah.
ini disesuaikan dgn kondisi KRS yg sebenarnya,
dimana di dalam 1 "lembar" KRS, mhs bisa
mengambil beberapa mata kuliah langsung
dlm semester yang sama.
*/
class cKRS{
private cMhs mhs;
//array of objects mata kuliah
private cMatkul mk[];
//counter indeks array matkul
private int jmk;
private int totalsks;
private String semester;
cKRS(){
mhs=null; mk=new cMatkul[10];
jmk=0; totalsks=0;
System.out.println("Object KRS dibuat...");
}
public void tambahMatkul(cMatkul m){
if((totalsks+m.getSKS()<=20)){
mk[jmk]=m;
jmk++;
totalsks=totalsks+m.getSKS();
System.out.println("Tambah MK Sukses...");
}
else{
System.out.println("Total SKS Melebihi Batas!");
}
}
public void hapusMatkul(String kd){
boolean ada=false;
for (int i = 0; i < jmk; i++) {
if(kd.equalsIgnoreCase(mk[i].getKodeMK())){
ada=true;
totalsks=totalsks-mk[i].getSKS();
mk[i]=null;
//majukan elemen2 array di belakang
//untuk mengisi elemen yg dihapus
for (int j = i; j < jmk; j++) {
if(j==jmk-1)
mk[j]=null;
else
mk[j]=mk[j+1];
}
jmk--;
System.out.println("Hapus MK Sukses!");
break;
}
}
if(ada==false){
System.out.println("Kode MK Tidak Ada!");
}
}
public void setMhs(cMhs m){
mhs=m;
}
public void setMatkul(cMatkul[] m){
mk=m;
}
public void setSemester(String s){
semester=s;
}
public int getJMK(){
return jmk;
}
public int getTotalSks(){
return totalsks;
}
public cMhs getMhs(){
return mhs;
}
public cMatkul[] getMatkul(){
return mk;
}
public String getSemester(){
return semester;
}
public String ToString(){
String temp = "KRS Semester "+semester+" - ";
temp = temp + mhs.getNama();
temp = temp + "\tSKS : "+totalsks;
temp = temp + "\nNo.\tKode\tNama MK\tSKS\n";
for (int i = 0; i < jmk; i++) {
temp = temp + (i+1)+"\t";
temp = temp + mk[i].getKodeMK()+"\t";
temp = temp + mk[i].getNamaMK()+"\t";
temp = temp + mk[i].getSKS()+"\n";
}
return temp;
}
}
No comments:
Post a Comment