ARRAY SATU DIMENSI
NAMA: SYURAINI NOOR CHAMSYAH
NPM : 22082010033
KELAS: PARALEL A
=======================ARRAY SATU DIMENSI=====================
SOURCE CODE:
package array;
import java.util.Scanner;
public class Array {
public static void main(String[] args) {
//deklarasi scanner
Scanner sc= new Scanner(System.in);
//===============================deklarasi variabel==========================================================
//array
String makanan[]=new String[10];
int jumlahporsi[]=new int[10];
int harga[]=new int[10];
int indx=0;
int total[]= new int[10];
int grandtotal=0;
int porsi=0;
int pilih;
//mulai program
System.out.println("===selamat datang di warung sederhana===");
do{
if(indx>=10){
System.out.println("keranjang penuh");
break;
}
System.out.println("silahkan pilih menu makanan");
System.out.println("1.nasi goreng");
System.out.println("2.mie goreng");
System.out.println("3.capcay");
System.out.println("4.nasi gila");
System.out.println("5.selesai");
//input pilihan menu utama
System.out.print("Masukan pilihan anda menggunakan angka: ");
pilih= sc.nextInt();
switch(pilih){
case 1:
makanan[indx]="nasi goreng"; harga[indx]=15000;
System.out.print("pesan berapa porsi: ");
porsi= sc.nextInt();
jumlahporsi[indx]= porsi;
indx++;
break;
case 2:
makanan[indx]="mie goreng"; harga[indx]=10000;
System.out.print("pesan berapa porsi: ");
porsi= sc.nextInt();
jumlahporsi[indx]= porsi;
indx++;
break;
case 3:
makanan[indx]="cap cay"; harga[indx]=8000;
System.out.print("pesan berapa porsi: ");
porsi= sc.nextInt();
jumlahporsi[indx]= porsi;
indx++;
break;
case 4:
makanan[indx]="nasi gila"; harga[indx]=15000;
System.out.print("pesan berapa porsi: ");
porsi= sc.nextInt();
jumlahporsi[indx]= porsi;
indx++;
break;
case 5:
System.out.println("terimakasih telah memesan");
break;
default:
System.out.print("maaf pesanan tidak sesuai");
}
}while(pilih!=5);
for (int i =0;i<indx;i++){
total[i]=jumlahporsi[i]*harga[i];
System.out.println((i+1)+". "+makanan[i]+" sebanyak "+jumlahporsi[i]+" porsi dengan harga satuan Rp "+ harga[i]);
System.out.println("total harga =Rp "+total[i]);
}
for (int i = 0; i <indx; i++) {
grandtotal=grandtotal+total[i];
}
System.out.println("======================================");
System.out.println("Total yang harus dibayar =Rp "+grandtotal);
System.out.println("======================================");
System.out.println("TERIMAKASIH TELAH BERKUNJUNG");
System.out.println("======================================");
}
}
OUTPUT:
Komentar
Posting Komentar