Latihan Array Multi Dimensi
Nama : Rayhan Qalby Ramadhan
NPM : 21082010008
Dipertemuan kali ini saya akan membahas tentang array multi dimensi tentang program kasir warung sederhana. Di program kali ini masih sama seperti kemarin bedanya sekarang program bisa melanjutkan untuk ke pembelian selanjutnya dan tidak ingin melanjutkan pembelian sehingga program pun selesai.
Source Code :
package array2D;
import java.util.Scanner;
public class appWarungMakan3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String pesanan[][]= new String[5][3];
int nominal[][] = new int[5][8];
int subtmkn = 0, subtmnm = 0, totalharga = 0;
int idx=0, idxmkn=0, idxmnm=0;
int pilih=0, pilih2=0, jumlah=0;
int cash, kembalian, out;
boolean ulang=true;
while(ulang){
System.out.println(" SELAMAT DATANG DI PODCAFE ");
System.out.println(" JL. CITANDUI NO. 14 ");
System.out.println(" SURABAYA ");
System.out.println("====================================");
do{
System.out.println("\nMENU");
System.out.println(" 1. Makanan");
System.out.println(" 2. Minuman");
System.out.println(" 3. Selesai");
System.out.print("Pilih = ");
pilih = sc.nextInt();
switch(pilih){
case 1:
System.out.println("\nDAFTAR MAKANAN");
System.out.println(" 1. Rice Bowl");
System.out.println(" 2. Chicken POP");
System.out.println(" 3. French Fries");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
switch(pilih2){
case 1:
pesanan[idxmkn][0]="Rice Bowl";
nominal[idxmkn][0]=31000;
break;
case 2 :
pesanan[idxmkn][0]="Chicken POP";
nominal[idxmkn][0]=25000;
break;
case 3:
pesanan[idxmkn][0]="French Fries";
nominal[idxmkn][0]=18000;
break;
}
System.out.print("Jumlah = ");
jumlah = sc.nextInt();
nominal[idxmkn][2]=jumlah; //jumlah makanan
//Hitung Biaya
nominal[idxmkn][4]=nominal[idxmkn][0]*nominal[idxmkn][2];
subtmkn = subtmkn + nominal[idxmkn][4];
idxmkn++;
break;
case 2:
System.out.println("\nDAFTAR MINUMAN");
System.out.println(" 1. Chocolate DJ");
System.out.println(" 2. Hazelnut Milk");
System.out.println(" 3. Mineral");
System.out.print("Pilih = ");
pilih2 = sc.nextInt();
switch(pilih2){
case 1:
pesanan[idxmnm][1]="Chocolate DJ";
nominal[idxmnm][1]=15000;
break;
case 2 :
pesanan[idxmnm][1]="Hazelnut Milk";
nominal[idxmnm][1]=16000;
break;
case 3:
pesanan[idxmnm][1]="Mineral";
nominal[idxmnm][1]=6000;
break;
}
System.out.print("Jumlah = ");
jumlah = sc.nextInt();
nominal[idxmnm][3]=jumlah; //jumlah minuman
//Hitung Biaya
nominal[idxmnm][5]=nominal[idxmnm][1]*nominal[idxmnm][3];
subtmnm = subtmnm + nominal[idxmnm][5];
idxmnm++;
break;
case 3:
System.out.println("Pemilihan Menu Selesai");
break;
default:
System.out.println("Pilihan Tidak Ada!!");
}
}while(pilih!=3);
System.out.println("============================================");
System.out.println("============= Daftar Pembelian =============");
System.out.println(" Makanan\tHarga\tJml\tTotal Biaya ");
for (int i = 0; i < 5; i++){
if(pesanan[i][0]!=null){
System.out.print((i+1)+"."+pesanan[i][0]);
System.out.print("\t"+nominal[i][0]);
System.out.print("\t"+nominal[i][2]);
System.out.println("\t"+nominal[i][4]);
System.out.println("");
}
}
System.out.println(" Minuman\tHarga\tJml\tTotal Biaya ");
for (int i = 0; i < 5; i++){
if(pesanan[i][1]!=null){
System.out.print((i+1)+"."+pesanan[i][1]);
System.out.print("\t"+nominal[i][1]);
System.out.print("\t"+nominal[i][3]);
System.out.println("\t"+nominal[i][5]);
System.out.println("");
}
}
System.out.println("============================================");
totalharga = subtmkn + subtmnm;
System.out.println("Tagihan :\t\t\t" +totalharga);
System.out.print("Bayar :\t\t\t");
cash = sc.nextInt();
System.out.print("Kembalian :");
System.out.println("\t\t\t" +(cash - totalharga));
System.out.println("============================================");
System.out.println("INGIN PESAN ULANG?");
System.out.println(" 1. Ya \n 2. Tidak");
System.out.print("Jawab = ");
out = sc.nextInt();
if(out == 2) {
ulang = false;
}
else if(out == 1) {
System.out.println("");
}
System.out.println("\n############################################");
System.out.println("============================================");
}
System.out.println("Terimakasih Atas Kunjungannya ");
System.out.println("Selamat Datang Kembali");
}
}
Tampilan Program di Netbeans :
Hasil Output :
Gambar diatas merupakan tampilan awal output setelah di run programnya. Di awal akan menampilkan nama tempat tersebut dan alamatnya. Pembeli akan disuruh untuk memilih menu yang tersedia yaitu makanan dan minuman.
Comments
Post a Comment