Perulangan Tunggal
Kode Program :
package bahasa_pemrograman_1;
import java.util.Scanner;
public class Perulangan {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int pilihmenu, pilihsub, diskon=0, total=0, totalakhir, jumlah;
String member,lagi;
System.out.println("================================");
System.out.println("Menu");
System.out.println("================================");
System.out.println("1.Sate :");
System.out.println(" 1).Ayam : 1.500 per tusuk");
System.out.println(" 2).Kambing : 3.000 per tusuk");
System.out.println("================================");
System.out.println("2.Pecel :");
System.out.println(" 1).Lauk ayam : 13.000 per porsi");
System.out.println(" 2).Lauk empal : 15.000 per porsi");
System.out.println("================================");
System.out.println("3.Penyetan :");
System.out.println(" 1).Lauk tahu / tempe : 5.000 per porsi");
System.out.println(" 2).Lauk telur : 7.000 per porsi");
System.out.println(" 3).Lauk ayam: 10.000 per porsi");
System.out.println("================================");
do {
System.out.print("Pilih menu (1,2 atau 3): ");
pilihmenu = input.nextInt();
totalakhir=total;
switch(pilihmenu){
case 1:
System.out.print("Pilih sub menu (contoh: 1): ");
pilihsub = input.nextInt();
if(pilihsub == 1){
System.out.print("Masukkan jumlah per tusuk : ");
jumlah = input.nextInt();
total=jumlah*1500;
System.out.println("Total : "+total);
total+=totalakhir;
}else if(pilihsub==2){
System.out.print("Masukkan jumlah per tusuk : ");
jumlah = input.nextInt();
total=jumlah*3000;
System.out.println("Total : "+total);
total+=totalakhir;
}else{
System.out.println("inputan salah");
}
break;
case 2:
System.out.print("Pilih sub menu (contoh: 1): ");
pilihsub = input.nextInt();
if(pilihsub == 1){
System.out.print("Masukkan jumlah per porsi : ");
jumlah = input.nextInt();
total=jumlah*13000;
System.out.println("Total : "+total);
total+=totalakhir;
}else if(pilihsub==2){
System.out.print("Masukkan jumlah per porsi : ");
jumlah = input.nextInt();
total=jumlah*15000;
System.out.println("Total : "+total);
total+=totalakhir;
}else{
System.out.println("inputan salah");
}
break;
case 3:
System.out.print("Pilih sub menu (contoh: 1): ");
pilihsub = input.nextInt();
switch(pilihsub){
case 1:
System.out.print("Masukkan jumlah porsi : ");
jumlah = input.nextInt();
total=jumlah*5000;
System.out.println("Total : "+total);
total+=totalakhir;
break;
case 2:
System.out.print("Masukkan jumlah porsi : ");
jumlah = input.nextInt();
total=jumlah*7000;
System.out.println("Total : "+total);
total+=totalakhir;
break;
case 3:
System.out.print("Masukkan jumlah porsi : ");
jumlah = input.nextInt();
total=jumlah*10000;
System.out.println("Total : "+total);
total+=totalakhir;
break;
}
break;
}
System.out.print("Apakah membeli lagi(iya/tidak)?");
lagi = input.next();
}while ("iya".equals(lagi));
if("tidak".equals(lagi)){
System.out.print("Punya member(contoh : iya)? ");
member = input.next();
if(member.equals("iya")){
diskon=total*5/100;
total-=diskon;
System.out.println("Total Akhir :"+total);
}else{
System.out.println("Total Akhir :"+total);
}
}
}
}
Hasil :
Komentar
Posting Komentar