looping "for"
posted by muhamad ade kurniawan
import java.io.*;public class pengulangan1{
byte nilAbsen=0, nilTugas=0, nilUTS=0, nilUAS=0;
BufferedReader objInput = new BufferedReader(new InputStreamReader(System.in));
void input(){
try{
System.out.println ("=================================================");
System.out.println ("\t\tInput Nilai Mahasiswa");
System.out.println ("=================================================");
System.out.print ("Nilai Absen\t :"); nilAbsen=Byte.parseByte(objInput.readLine());
System.out.print ("Nilai Tugas\t :"); nilTugas=Byte.parseByte(objInput.readLine());
System.out.print ("Nilai UTS\t :"); nilUTS=Byte.parseByte(objInput.readLine());
System.out.print ("Nilai UAS\t :"); nilUAS=Byte.parseByte(objInput.readLine());
}
catch(Exception e){
System.out.println ("Error: "+e);
}
}
void cetak(){
System.out.println ("===================================");
System.out.println ("\t\tInput Nilai Mahasiswa");
System.out.println ("===================================");
System.out.println ("Nilai Absen\t :"+nilAbsen);
System.out.println ("Nilai Tugas\t :"+nilTugas);
System.out.println ("Nilai UTS\t :" +nilUTS);
System.out.println ("Nilai UAS\t :" +nilUAS);
int total=((nilAbsen*10/100)+(nilTugas*20/100)+(nilUTS*30/100)+(nilUAS*40/100));
char grade = '-';
String predikat="-";
if (total >=35)
if (total >=60)
if (total >=75)
if (total >=85)
grade='A';
else
grade='B';
else
grade='C';
else
grade='D';
else
grade='E';
switch(grade){
case 'A':
predikat="Very Nice";
break;
case 'B':
predikat="Good";
break;
case 'C':
predikat="Not BAD";
break;
case 'D':
predikat="BAD";
break;
case 'E':
predikat="Very BAD";
break;
}
System.out.println ("===================================");
System.out.println ("Nilai Total :"+total);
System.out.println ("Grade :"+grade);
System.out.println ("Predikat : "+predikat);
System.out.println ("===================================");
}
public static void main(String[] args){
pengulangan1 objInput=new pengulangan1();
String pil="";
for (int i=0; i<5; i++){
objInput.input();
objInput.cetak();
try{
System.out.print("Mau Input Lagi ? [Y/N] = "); pil = objInput.objInput.readLine();
switch(pil){
case "N":
case "n":
System.exit(0);
}
}
catch(Exception e){
}
}
}
}
0 comments:
Post a Comment