Program Sistem Informasi LAB

Dalam tulisan kali ini saya ingin meberikan contoh bagaimana membuat program menggunakan JAVA berupa pemberian input dan output pada JAVA.

Berikut contohnya:

1. Pertama buat project baru.

2. Buat kelas baru dengan nama SILab. Tulisakan source code nya seperti dibawah ini:

import java.io.*;
public class SILab {
static String x[] = new String[100];
static int y[] = new int[100];
static int i = 0;
static int w;
public void tambahAlat(){
System.out.print("Masukkan Alat : ");
BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
String menu = null;
try{
menu = input.readLine();
}
catch (IOException e ) {
}
y[i] = i+1;
x[i] = menu;
i++;
System.out.print(x[i-1]+" telah dimasukkan");
}
public void hapusAlat(){
for(int c = 0; c <= (i-1); c++){
System.out.println(y[c] + ". "+ x[c]);
}
System.out.print("Pilih no item yang akan dihapus : ");
BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
String menu = null;
try{
menu = input.readLine();
}
catch (IOException e ) {
}
w = Integer.parseInt(menu);
x[w-1] = "Alat sudah tidak eksis!";
}
public void cekAlat(){
for(int c = 0; c <= (i-1); c++){
System.out.println(y[c] + ". "+ x[c]);
}
}
}

3. Buat kelas MAIN dengan nama MainSILab. Tuliskan source code nya seperti di bawah ini:

import java.io.*;
public class MainSILab {
static int i ;
static SILab a = new SILab ();
public static void main(String[] args) {
MainSILab m = new MainSILab();
System.out.println("Sistem Informasi Laboratorium");
m.start();
}
public void start(){
MainSILab k = new MainSILab();
k.startmenu();
k.inputdata();
k.pilihmenu();
}
public void startmenu(){
System.out.println("\nLaboratorium Software");
System.out.println("piih menu:");
System.out.println("1. menambah peralatan lab");
System.out.println("2. menghapus peralatan lab");
System.out.println("3. Cek peralatan lab yang tersedia");
System.out.println("4. Keluar");
System.out.print("Pilih [1-4]:");
}
public void inputdata(){
BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
String menu = null;
try{
menu = input.readLine();
}
catch (IOException e ) {
}
i = Integer.parseInt(menu);
}
public void pilihmenu(){
MainSILab n = new MainSILab();
SILab a = new SILab();
switch(i){
case 1:
System.out.println("1.menambah peralatan");
a.tambahAlat();
n.start();
case 2:
System.out.println("2.hapus peralatan");
a.hapusAlat();
n.start();
case 3 :
System.out.println("3.Cek peralatan");
a.cekAlat();
n.start();
case 4 :
System.out.println("4. Keluar");
System.exit(0);
default:
n.start();
}
}
}

4. Tampilan Main class nya apabila dijalankan pada command prompt, seperti di bawah ini:

Capture1 Capture2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s