Menu with case (method)


Oleh :
arif zainurrohman 

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package praktikum;

/**
*
* @author Arif
*/
import java.util.Scanner;
public class menucase {
String [] nama = {"JATI","SANTI","NISA","RINTO","SUSI"};
String [] kelas = new String [nama.length];
char d;
double a = 80.50;
double b = 75.00;
double c = (0.3 * a)+(0.7*b); 

void cetakNama() {
int i = 0;
System.out.println(nama[i] + " " + kelas[i]);
i++; 
System.out.println(nama[i] + " " + kelas[i]);
i++;
System.out.println(nama[i] + " " + kelas[i]);
i++;
System.out.println(nama[i] + " " + kelas[i]); 
i++;
System.out.println(nama[i] + " " + kelas[i]); 
i++;
}

void Kondisi(){ 
if (c >= 80){
d = 'A';
}
else if (c >= 70){
d = 'B';
}
else if (c >= 50){
d = 'C';
}
else if (c >= 30){
d = 'D';
}
else {
d = 'e';
}
} 

void cobaa (){
int d = 0;
int a = 20/d;
}

public static void main(String[] args){
menucase a = new menucase ();
menucase o = new menucase ();
menucase p = new menucase ();
do
{
System.out.println("");
System.out.println("Menu Aplikasi Praktikum :");
System.out.println("1. Array");
System.out.println("2. if-elseif-else");
System.out.println("3. Try Catch ");
System.out.println("0. Keluar");
Scanner pilih = new Scanner(System.in);
System.out.print("Masukan Pilihan Anda : ");
int pilihan = pilih.nextInt();
switch(pilihan)
{
case 1: 
System.out.println(" ");
System.out.println("-------------------------------");
System.out.println("-------------------------------");
a.kelas[0] = "31A03";
a.kelas[1] = "41A01";
a.kelas[2] = "21A01";
a.kelas[3] = "31A07";
a.kelas[4] = "51A01";
a.cetakNama();
System.out.println("-------------------------------");
break;
case 2:
o.Kondisi();
System.out.println("Nilai Akhir : "+o.c);
System.out.println("Keterangan : "+o.d);
break;
case 3: 
try{ 
p.cobaa();}
catch (ArithmeticException e){ 
System.out.println("Division By Zero");
}
break;
case 0:
System.exit(0);
default:
System.out.println("maaf !! Pilihan tidak ada !! ");
break;
}
}
while(true);
}
}



Ibu Kota ,  7 Desember 2013
akhukum fillah arif zainurrohman