Dalam program kali ini dibuatkan tampilan menu untuk membuat object, menghapus object, dan menjalankan method standar yang dimiliki oleh class Mahasiswa dan class Mata Kuliah. Menu program dibuat di dalam class aplikasi; yaitu class utama yang di dalamnya terdapat method main. Berikut ini adalah source code programnya.
package pkgSIAMIK;
import java.util.Scanner;
public class appSIAMIK {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
cMhs mhs=null;
cMatkul mk=null;
cKRS krs=null;
int pilih, pilih2;
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. Exit");
System.out.print("Pilih = ");
pilih = sc.nextInt();
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 ==");
System.out.print("Masukkan Nama = ");
sc = new Scanner(System.in);
String nama = sc.nextLine();
System.out.print("Masukkan NPM = ");
String npm = sc.next();
mhs = new cMhs(npm, nama);
break;
case 2:
System.out.println("== Hapus Mhs ==");
System.out.print("Masukkan NPM = ");
npm = sc.next();
if(mhs != null && mhs.getNPM().equalsIgnoreCase(npm))
{
System.out.println("Data ditemukan");
System.out.println("Dihapus? 1.Ya, 2.Tidak");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
if(pilih2==1){
mhs = null;
System.out.println("Data dihapus...");
}
else System.out.println("Batal hapus...");
}
else System.out.println("Data tidak ada...");
break;
case 3:
System.out.println("== Update Data ==");
System.out.print("Masukkan NPM = ");
npm = sc.next();
if(mhs != null && mhs.getNPM().equalsIgnoreCase(npm))
{
System.out.println("Data ditemukan");
System.out.print("Nama baru = ");
sc = new Scanner(System.in);
String nm = sc.nextLine();
System.out.print("IPK baru = ");
double ip = sc.nextDouble();
System.out.println("Simpan? 1.Ya, 2.Tidak");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
if(pilih2==1){
mhs.setNama(nm);
mhs.setIPK(ip);
System.out.println("Data diperbarui...");
}
else System.out.println("Batal update...");
}
else System.out.println("Data tidak ada...");
break;
case 4:
System.out.println("== Lihat Data ==");
if(mhs!=null){
System.out.println("NPM : "+mhs.getNPM());
System.out.println("Nama : "+mhs.getNama());
System.out.println("IPK : "+mhs.getIPK());
}
else System.out.println("Data kosong...");
break;
case 5:
System.out.println("== Query Data ==");
if(mhs!=null)
System.out.println(mhs.ToString());
else System.out.println("Data kosong...");
break;
}
break;
case 2:
System.out.println("Sub Menu Mata Kuliah");
System.out.println("1. Tambah 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 Matkul ==");
System.out.print("Masukkan Nama = ");
sc = new Scanner(System.in);
String nama = sc.nextLine();
System.out.print("Masukkan Kode = ");
String kd = sc.next();
System.out.print("Masukkan SKS = ");
int sks = sc.nextInt();
mk = new cMatkul(kd, nama, sks);
break;
case 2:
System.out.println("== Hapus Matkul ==");
System.out.print("Masukkan Kode MK = ");
kd = sc.next();
if(mk != null && mk.getKodeMK().equalsIgnoreCase(kd))
{
System.out.println("Data ditemukan");
System.out.println("Dihapus? 1.Ya, 2.Tidak");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
if(pilih2==1){
mk = null;
System.out.println("Data dihapus...");
}
else System.out.println("Batal hapus...");
}
else System.out.println("Data tidak ada...");
break;
case 3:
System.out.println("== Update Data ==");
System.out.print("Masukkan Kode MK = ");
kd = sc.next();
if(mk != null && mk.getKodeMK().equalsIgnoreCase(kd))
{
System.out.println("Data ditemukan");
System.out.print("Nama baru = ");
sc = new Scanner(System.in);
String nm = sc.nextLine();
System.out.print("SKS baru = ");
sks = sc.nextInt();
System.out.println("Simpan? 1.Ya, 2.Tidak");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
if(pilih2==1){
mk.setNamaMK(nm);
mk.setSKS(sks);
System.out.println("Data diperbarui...");
}
else System.out.println("Batal update...");
}
else System.out.println("Data tidak ada...");
break;
case 4:
System.out.println("== Lihat Data ==");
if(mk!=null){
System.out.println("Kode MK : "+mk.getKodeMK());
System.out.println("Nama : "+mk.getNamaMK());
System.out.println("SKS : "+mk.getSKS());
}
else System.out.println("Data kosong...");
break;
case 5:
System.out.println("== Query Data ==");
if(mk!=null)
System.out.println(mk.ToString());
else System.out.println("Data kosong...");
break;
}
break;
case 3:
System.out.println("Sub Menu KRS");
System.out.println("1. Tambah KRS");
System.out.println("2. Hapus KRS");
System.out.println("3. Update Data");
System.out.println("4. Cetak Data");
System.out.println("5. Query");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
break;
case 4:
System.out.println("Terima kasih...");
}
}while (pilih!=4);
}
}
Untuk source code file class providernya bisa diklik di link berikut:
No comments:
Post a Comment