package pkgSIAMIK;
import java.util.Scanner;
public class appSIAMIK3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//object-object utama/ master di MAIN
//sementara dibatasi 3 org dulu
cMhs mhs[]=new cMhs[3];
//buat object mhs uji coba
mhs[0]=new cMhs();
mhs[0].setNPM("123");
mhs[0].setNama("Budi");
mhs[0].setIPK(3.45);
//sementara dibatasi 5 matkul saja
cMatkul mk[]=new cMatkul[5];
//buat object matkul uji coba
mk[0]=new cMatkul();
mk[0].setKodeMK("111");
mk[0].setNamaMK("BP2");
mk[0].setSKS(3);
mk[1]=new cMatkul();
mk[1].setKodeMK("222");
mk[1].setNamaMK("Basdat");
mk[1].setSKS(3);
mk[2]=new cMatkul();
mk[2].setKodeMK("333");
mk[2].setNamaMK("IMK");
mk[2].setSKS(3);
//object yg mengandung relasi
//satu object KRS utk 1 mhs dan banyak matkul
//sementara dibatasi 3 KRS saja
cKRS krs[]=new cKRS[3];
//satu prodi bisa memiliki banyak mhs
//sementara dibatasi ada 2 prodi saja
cProdi prodi[]=new cProdi[2];
//buat object prodi uji coba
prodi[0]=new cProdi();
prodi[0].setKodeProdi("082");
prodi[0].setNamaProdi("Sistem Informasi");
prodi[0].setAkreditasi("B");
//variabel2 pendukung
int pilih, pilih2;
//untuk menyimpan indeks array object
//di MAIN
int jmhs, jmk, jkrs=0, jpro;
//untuk menyimpan jumlah elemen maksimal
//array of object di MAIN
int maxmhs=3, maxmk=5, maxkrs=3, maxpro=2;
jmhs=1; jmk=3; jpro=1;
do{
System.out.println("\nMENU SIAMIK");
System.out.println("1. Mahasiswa");
System.out.println("2. Mata Kuliah");
System.out.println("3. Kartu Rencana Studi");
System.out.println("4. Program Studi");
System.out.println("5. Exit");
System.out.print("Pilih = ");
pilih = sc.nextInt();
System.out.println("");
switch(pilih){
case 1:
System.out.println("Sub Menu Mahasiswa");
System.out.println("1. Tambah Mhs");
System.out.println("2. Hapus Mhs");
System.out.println("3. Update Data");
System.out.println("4. Cetak Data");
System.out.println("5. Query");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
switch(pilih2){
case 1:
System.out.println("== Tambah Mhs ==");
//jumlah mhs masih di bawah kapasitas maksimal
if(jmhs<maxmhs){
System.out.print("Masukkan Nama = ");
sc = new Scanner(System.in);
String nama = sc.nextLine();
String npm="";
//cek apakah NPM sdh dipakai
boolean sudahada;
do{
System.out.print("Masukkan NPM = ");
npm = sc.next();
sudahada=false;
for (int i = 0; i < jmhs; i++) {
if(mhs[i].getNPM().equalsIgnoreCase(npm)){
sudahada=true;
break;
}
}
if(sudahada){
System.out.println(" NPM Sudah Ada!");
}
}while(sudahada==true);
//simpan di array object mhs di MAIN
mhs[jmhs] = new cMhs(npm, nama);
jmhs++;
System.out.println("Penambahan Sukses...");
}
else{
System.out.println("Kapasitas Penuh!");
}
break;
case 2:
System.out.println("== Hapus Mhs ==");
//jumlah object mhs harus minimal 1
if(jmhs>0){
System.out.print("Masukkan NPM = ");
String npm = sc.next();
//cari di array object mhs di MAIN
boolean ketemu=false;
for (int i = 0; i < jmhs; i++) {
if(mhs[i].getNPM().equalsIgnoreCase(npm)){
ketemu=true;
System.out.println("Data Ditemukan!");
System.out.println("Dihapus? 1.Ya, 2.Tidak");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
if(pilih2==1){
//hapus elemen array object di MAIN
mhs[i] = null;
//geser maju utk 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("Penghapusan Berhasil...");
}
else System.out.println("Batal Hapus!");
break;
}
}
if(!ketemu){
System.out.println("NPM Tidak Ada!");
}
}
else System.out.println("Data Mhs Kosong!");
break;
case 3:
System.out.println("== Update Data ==");
//jumlah object mhs harus minimal 1
if(jmhs>0){
System.out.print("Masukkan NPM = ");
String npm = sc.next();
//cari NPM di array object di MAIN
boolean ketemu=false;
for (int i = 0; i < jmhs; i++) {
if(mhs[i].getNPM().equalsIgnoreCase(npm)){
ketemu=true;
System.out.println("Data Ditemukan!");
//skenarionya update ipk mhs
System.out.print("Masukkan IPK Baru = ");
double ip = sc.nextDouble();
System.out.println("Simpan? 1.Ya, 2.Tidak");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
if(pilih2==1){
//update elemen array object di MAIN
mhs[i].setIPK(ip);
System.out.println("Update Sukses...");
}
else System.out.println("Batal Update!");
break;
}
}
if(!ketemu){
System.out.println("NPM Tidak Ada!");
}
}
else System.out.println("Data Mhs Kosong!");
break;
case 4:
System.out.println("== Lihat Data ==");
//object mhs harus ada dulu
if(jmhs>0){
System.out.println("No.\tNPM\tNama\tIPK");
for (int i = 0; i < jmhs; i++) {
System.out.print((i+1)+". ");
System.out.print(mhs[i].getNPM()+"\t");
System.out.print(mhs[i].getNama()+"\t");
System.out.println(mhs[i].getIPK());
}
}
else System.out.println("Data Mhs kosong!");
break;
case 5:
System.out.println("== Query Data ==");
//object mhs harus ada dulu
if(jmhs>0){
for (int i = 0; i < jmhs; i++) {
System.out.println(mhs[i].ToString());
}
}
else System.out.println("Data Mhs kosong!");
break;
}
break;
case 2:
System.out.println("Sub Menu Mata Kuliah");
System.out.println("1. Buat Mata Kuliah");
System.out.println("2. Hapus Mata Kuliah");
System.out.println("3. Update Data");
System.out.println("4. Cetak Data");
System.out.println("5. Query");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
switch(pilih2){
case 1:
System.out.println("== Tambah Mata Kuliah ==");
if(jmk<maxmk){
System.out.print("Masukkan Nama = ");
sc = new Scanner(System.in);
String nama = sc.nextLine();
String kode="";
//cek apakah kode sdh dipakai
boolean sudahada;
do{
System.out.print("Masukkan Kode = ");
kode = sc.next();
sudahada=false;
for (int i = 0; i < jmk; i++) {
if(mk[i].getKodeMK().equalsIgnoreCase(kode)){
sudahada=true;
break;
}
}
if(sudahada){
System.out.println(" Kode Sudah Ada!");
}
}while(sudahada==true);
System.out.print("Masukkan SKS = ");
int sks = sc.nextInt();
//simpan di array object mk di MAIN
mk[jmk] = new cMatkul(kode, nama, sks);
jmk++;
System.out.println("Penambahan Sukses...");
}
else{
System.out.println("Kapasitas Penuh!");
}
break;
case 2:
System.out.println("== Hapus Mata Kuliah ==");
if(jmk>0){
System.out.print("Masukkan Kode = ");
String kode = sc.next();
//cari di array object mk di MAIN
boolean ketemu=false;
for (int i = 0; i < jmk; i++) {
if(mk[i].getKodeMK().equalsIgnoreCase(kode)){
ketemu=true;
System.out.println("Data Ditemukan!");
System.out.println("Dihapus? 1.Ya, 2.Tidak");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
if(pilih2==1){
//hapus elemen array object di MAIN
mk[i] = null;
//geser maju utk 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("Penghapusan Berhasil...");
}
else System.out.println("Batal Hapus!");
break;
}
}
if(!ketemu){
System.out.println("Kode Tidak Ada!");
}
}
else System.out.println("Data Mata Kuliah Kosong!");
break;
case 3:
System.out.println("== Update Data ==");
if(jmk>0){
System.out.print("Masukkan Kode = ");
String kode = sc.next();
//cari kode di array object di MAIN
boolean ketemu=false;
for (int i = 0; i < jmk; i++) {
if(mk[i].getKodeMK().equalsIgnoreCase(kode)){
ketemu=true;
System.out.println("Data Ditemukan!");
System.out.print("Masukkan SKS Baru = ");
int sks = sc.nextInt();
System.out.println("Simpan? 1.Ya, 2.Tidak");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
if(pilih2==1){
//update elemen array object di MAIN
mk[i].setSKS(sks);
System.out.println("Update Sukses...");
}
else System.out.println("Batal Update!");
break;
}
}
if(!ketemu){
System.out.println("Kode Tidak Ada!");
}
}
else System.out.println("Data Mata Kuliah Kosong!");
break;
case 4:
System.out.println("== Lihat Data ==");
if(jmk>0){
System.out.println("No.\tKode\tNama\tSKS");
for (int i = 0; i < jmk; i++) {
System.out.print((i+1)+". ");
System.out.print(mk[i].getKodeMK()+"\t");
System.out.print(mk[i].getNamaMK()+"\t");
System.out.println(mk[i].getSKS());
}
}
else System.out.println("Data Mata Kuliah kosong!");
break;
case 5:
System.out.println("== Query Data ==");
if(jmk>0){
for (int i = 0; i < jmk; i++) {
System.out.println(mk[i].ToString());
}
}
else System.out.println("Data Mata Kuliah kosong!");
break;
}
break;
case 3:
System.out.println("Sub Menu KRS Mahasiswa");
System.out.println("1. Buat KRS Baru");
System.out.println("2. Hapus KRS");
System.out.println("3. Ambil Mata Kuliah");
System.out.println("4. Drop Mata Kuliah");
System.out.println("5. Cetak KRS");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
switch(pilih2){
case 1:
if(jkrs<maxkrs){
System.out.println("== Buat KRS Baru ==");
System.out.print("Masukkan NPM = ");
String npm = sc.next();
System.out.print("Masukkan Semester = ");
String smt = sc.next();
//validasi mhs ke array object di MAIN
boolean ketemu=false;
for (int i = 0; i < jmhs; i++) {
if(mhs[i]!=null && mhs[i].getNPM().equalsIgnoreCase(npm)){
ketemu=true;
krs[jkrs]=new cKRS();
krs[jkrs].setMhs(mhs[i]);
krs[jkrs].setSemester(smt);
jkrs++;
System.out.println("KRS Baru Sukses...");
break;
}
}
if(ketemu==false){
System.out.println("NPM Tidak Ada!");
}
} else{
System.out.println("Kapasitas KRS Penuh!");
}
break;
case 2:
if(jkrs>0){
System.out.println("== Hapus KRS ==");
System.out.print("Masukkan NPM = ");
String npm = sc.next();
System.out.print("Masukkan Semester = ");
String smt = sc.next();
//validasi mhs, dan semester
boolean ketemu=false;
for (int i = 0; i < jkrs; i++) {
if(krs[i]!=null && krs[i].getMhs().getNPM().equalsIgnoreCase(npm)){
if(krs[i].getSemester().equalsIgnoreCase(smt)){
ketemu=true;
System.out.println("Dihapus? 1.Ya, 2.Tidak");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
if(pilih2==1){
//hapus elemen array object di MAIN
krs[i] = null;
//geser maju utk mengisi elemen yg dihapus
for (int j = i; j < jkrs; j++) {
if(j==jkrs-1)
krs[j]=null;
else
krs[j]=krs[j+1];
}
jkrs--;
System.out.println("Penghapusan Berhasil...");
}
else System.out.println("Batal Hapus!");
break;
}
}
}
if(ketemu==false){
System.out.println("KRS Mhs Tidak Ada!");
}
}
else{
System.out.println("KRS Belum Ada!");
}
break;
case 3:
if(jkrs>0){
System.out.println("== Ambil Mata Kuliah ==");
System.out.print("Masukkan NPM = ");
String npm = sc.next();
System.out.print("Masukkan Semester = ");
String smt = sc.next();
//validasi mhs, semester, kode mk baru
boolean ketemu=false;
for (int i = 0; i < jkrs; i++) {
if(krs[i]!=null && krs[i].getMhs().getNPM().equalsIgnoreCase(npm)){
if(krs[i].getSemester().equalsIgnoreCase(smt)){
ketemu=true;
System.out.print("Masukkan Kode MK = ");
String kd = sc.next();
//validasi kode MK ke array mk di MAIN
boolean ada=false;
for (int j = 0; j < jmk; j++) {
if(mk[j]!=null && mk[j].getKodeMK().equalsIgnoreCase(kd)){
ada=true;
System.out.println("Tambah? 1.Ya, 2.Tidak");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
if(pilih2==1){
//simpan ke array object MK di KRS
krs[i].tambahMatkul(mk[j]);
}
else System.out.println("Batal Tambah!");
break;
}
}
if(ada==false){
System.out.println("Kode MK Tidak Ada!");
}
break;
}
}
}
if(ketemu==false){
System.out.println("KRS Mhs Tidak Ada!");
}
}
else{
System.out.println("KRS Belum Ada!");
}
break;
case 5:
if(jkrs>0){
System.out.println("== Cetak KRS Mhs ==");
System.out.print("Masukkan NPM = ");
String npm = sc.next();
System.out.print("Masukkan Semester = ");
String smt = sc.next();
//validasi mhs, semester
boolean ketemu=false;
for (int i = 0; i < jkrs; i++) {
if(krs[i]!=null && krs[i].getMhs().getNPM().equalsIgnoreCase(npm)){
if(krs[i].getSemester().equalsIgnoreCase(smt)){
ketemu=true;
if(krs[i].getJMK()>0){
System.out.println(krs[i].ToString());
}
else System.out.println("KRS Belum Diisi!");
break;
}
}
}
if(ketemu==false){
System.out.println("KRS Mhs Tidak Ada!");
}
}
else System.out.println("KRS Kosong!");
break;
case 4:
if(jkrs>0){
System.out.println("== Drop Mata Kuliah ==");
System.out.print("Masukkan NPM = ");
String npm = sc.next();
System.out.print("Masukkan Semester = ");
String smt = sc.next();
//validasi mhs, semester, kode mk ke array object di KRS
boolean ketemu=false;
for (int i = 0; i < jkrs; i++) {
if(krs[i]!=null && krs[i].getMhs().getNPM().equalsIgnoreCase(npm)){
if(krs[i].getSemester().equalsIgnoreCase(smt)){
//tampilkan daftar MK yg ada di KRS Mhs
cMatkul t[] = krs[i].getMatkul();
System.out.println(" Daftar Isi KRS");
for (int j = 0; j < krs[i].getJMK(); j++) {
System.out.print(" "+t[j].getKodeMK()+"\t");
System.out.println(t[j].getNamaMK());
}
System.out.print("Masukkan Kode MK = ");
String kd = sc.next();
//validasi kode MK ke array mk di KRS
for (int j = 0; j < jmk; j++) {
if(t[j].getKodeMK().equalsIgnoreCase(kd)){
ketemu=true;
System.out.println("Drop? 1.Ya, 2.Tidak");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
if(pilih2==1){
//simpan ke array object MK di KRS
krs[i].hapusMatkul(kd);
}
else System.out.println("Batal Tambah!");
break;
}
}
break;
}
}
}
if(ketemu==false){
System.out.println("KRS Mhs Tidak Ada!");
}
}
else{
System.out.println("KRS Belum Ada!");
}
break;
}
break;
case 4:
System.out.println("Sub Menu Prodi");
System.out.println("1. Buat Prodi");
System.out.println("2. Update Data Prodi");
System.out.println("3. Tambah Mahasiswa");
System.out.println("4. Hapus Mahasiswa");
System.out.println("5. Lihat Mahasiswa");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
switch(pilih2){
case 1:
if(jpro<maxpro){
System.out.println("== Buat Prodi ==");
boolean sudahada;
String kd;
//cek kode apakah sdh ada di array prodi di MAIN
do{
sudahada=false;
System.out.print("Masukkan Kode = ");
kd = sc.next();
for (int i = 0; i < jpro; i++) {
if(prodi[i].getKodeProdi().equalsIgnoreCase(kd)){
sudahada=true;
}
}
}while(sudahada==true);
System.out.print("Masukkan Nama = ");
sc = new Scanner(System.in);
String nm = sc.nextLine();
System.out.print("Masukkan Akreditasi = ");
String ak = sc.next();
prodi[jpro] = new cProdi(kd, nm, ak);
jpro++;
System.out.println("Prodi Berhasil Dibuat!");
}
else System.out.println("Kapasitas Prodi Penuh!");
break;
case 2:
if(jpro>0){
System.out.println("== Update Data ==");
System.out.print("Masukkan Kode Prodi = ");
String kd = sc.next();
//cek kode prodi ke array object Prodi di MAIN
boolean ada=false;
for (int i = 0; i < jpro; i++) {
if(prodi[i]!= null && prodi[i].getKodeProdi().equalsIgnoreCase(kd))
{
ada=true;
System.out.print("Akreditasi baru = ");
String ak = sc.next();
System.out.println("Update? 1.Ya, 2.Tidak");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
if(pilih2==1){
prodi[i].setAkreditasi(ak);
System.out.println("Update sukses...");
}
else System.out.println("Batal update...");
break;
}
}
if(!ada){
System.out.println("Kode Prodi Tidak Ada!");
}
}
else System.out.println("Prodi Masih Kosong!");
break;
case 3:
if(jpro>0){
System.out.println("== Tambah Mahasiswa ==");
System.out.print("Masukkan NPM = ");
String npm = sc.next();
//validasi dulu mhs ke array object mhs di MAIN
boolean ketemu=false;
for (int i = 0; i < jmhs; i++) {
if(mhs[i]!=null && mhs[i].getNPM().equalsIgnoreCase(npm)){
ketemu=true;
System.out.println("Tambah? 1.Ya, 2.Tidak");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
if(pilih2==1){
//simpan ke array object mhs di PRODI
prodi[i].addMhs(mhs[i]);
}
else System.out.println("Batal Tambah!");
break;
}
}
if(ketemu==false){
System.out.println("NPM Tidak Ada!");
}
}
else{
System.out.println("Prodi Belum Ada!");
}
break;
case 4:
if(jpro>0){
System.out.println("== Hapus Mahasiswa ==");
//validasi mhs ke array object mhs di PRODI
boolean ketemu=false;
for (int i = 0; i < jkrs; i++) {
if(prodi[i]!=null){
//tampilkan daftar Mhs yg ada di PRODI
cMhs t[] = prodi[i].getMhs();
System.out.println(" Daftar Mhs Prodi");
for (int j = 0; j < prodi[i].getJMhs(); j++) {
System.out.print(" "+t[j].getNPM()+"\t");
System.out.println(t[j].getNama());
}
System.out.print("Masukkan NPM = ");
String kd = sc.next();
//validasi npm ke array mhs di PRODI
for (int j = 0; j < jmk; j++) {
if(t[j].getNPM().equalsIgnoreCase(kd)){
ketemu=true;
System.out.println("Hapus? 1.Ya, 2.Tidak");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
if(pilih2==1){
//hapus array object mhs di PRODI
prodi[i].deleteMhs(kd);
}
else System.out.println("Batal Hapus!");
break;
}
}
break;
}
}
if(ketemu==false){
System.out.println("NPM Mhs Tidak Ada!");
}
}
else{
System.out.println("Prodi Belum Ada!");
}
break;
case 5:
if(jpro>0){
System.out.println("== Lihat Mahasiswa ==");
System.out.print("Masukkan Kode Prodi = ");
String kd = sc.next();
//validasi kode ke array object prodi di MAIN
boolean ketemu=false;
for (int i = 0; i < jpro; i++) {
if(prodi[i]!=null && prodi[i].getKodeProdi().equalsIgnoreCase(kd)){
ketemu=true;
cMhs t[] = prodi[i].getMhs();
System.out.println("NPM\tNama\tIPK");
for (int j = 0; j < prodi[i].getJMhs(); j++) {
System.out.print(t[j].getNPM());
System.out.print("\t"+t[j].getNama());
System.out.println("\t"+t[j].getIPK());
}
break;
}
}
if(ketemu==false){
System.out.println("Prodi Tidak Ada!");
}
}
else System.out.println("Prodi Masih Kosong!");
break;
}
break;
case 5:
System.out.println("Terima kasih...");
}
}while (pilih!=5);
}
}
No comments:
Post a Comment