16 Maret, 2009

OOP - ProgramHitung

Berikut saya ambil cuplikannya :

public class ProgramHitung{
public static void main(String[] args){
String dataString;
int pilihan=0,N1,N2;
int lagi=0;

//System.out.println(" Menu ");
System.out.println(" Menu Program Perhitungan ");
System.out.println("============================ ");

System.out.println(" 1. Penambahan ");
System.out.println(" 2. Pengurangan ");
System.out.println(" 3. Pembagian ");
System.out.println(" 4. Perkalian ");
System.out.println("============================ ");
while(lagi==0){
System.out.println(" ");
System.out.print("Input Nilai 1 = ");
dataString=InputKeyboard.inputString();
N1=Integer.valueOf(dataString).intValue();
System.out.println(" ");
System.out.print("Input Nilai 2 = ");
dataString=InputKeyboard.inputString();
N2=Integer.valueOf(dataString).intValue();
System.out.println(" ");
System.out.print("Pilih Proses [1/2/3/4]= ");
dataString=InputKeyboard.inputString();
pilihan=Integer.valueOf(dataString).intValue();
System.out.println(" ");

Matematika baru = new Matematika();

switch(pilihan){
case 1:
//baru.tambahNilai(N1,N2);
System.out.println("Hasil Pertambahan " + N1 + " + " + N2 + " = " + baru.tambahNilai(N1,N2));
break;

case 2:
//baru.kurangNilai(N1,N2);
System.out.println("Hasil Pengurangan " + N1 + " - " + N2 + " = " + baru.kurangNilai(N1,N2));
break;
case 3:

//baru.bagiNilai(N1,N2);
System.out.println("Hasil Pembagian " + N1 + " / " + N2 + " = " + baru.bagiNilai(N1,N2));
break;

case 4:
//baru.kaliNilai(N1,N2);
System.out.println("Hasil Perkalian " + N1 + " * " + N2 + " = " + baru.kaliNilai(N1,N2));
break;

default:
System.out.println("Silakan Pilih 1, 2 atau 3");
}
System.out.println("============================= ");
System.out.println("");
System.out.print("Coba Lagi ? [0=Ya] = ");
dataString=InputKeyboard.inputString();
lagi=Integer.valueOf(dataString).intValue();
System.out.println("");
System.out.println("Terima Kasih.......");
}
}
}