Aplikasi Kasir Kedai (Searching)
Nama : Rayhan Qalby Ramadhan
NPM : 21082010008
Tampilan Program :
Source Code :
package searching;
import java.util.Scanner;
public class AppWarungMakan {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//array
String menuMakanan[] = new String[10];
int harga[] = new int[10];
int jumlah[] = new int[5];
String beliMakan[] = new String[5];
int beliHarga[] = new int[5];
String cariMakan[] = new String[10];
int cariHarga[] = new int[10];
int jumlahBeli = 0;
int totalHarga = 0;
int subTotal[] = new int[10];
int inputUangTunai, uangKembalian;
//inisialisasi array
menuMakanan[0] = "Mie Ayam Jamur";
harga[0] = 10000;
menuMakanan[1] = "Mie Ayam Ceker";
harga[1] = 9000;
menuMakanan[2] = "Mie Ayam Jawa";
harga[2] = 12000;
menuMakanan[3] = "Mie Ayam Kare";
harga[3] = 11000;
menuMakanan[4] = "Bakso Sapi";
harga[4] = 8000;
menuMakanan[5] = "Bakso Aci";
harga[5] = 11000;
menuMakanan[6] = "Bakso Malang";
harga[6] = 10000;
menuMakanan[7] = "Bakso Keju";
harga[7] = 12000;
menuMakanan[8] = "Bakso Beranak";
harga[8] = 14000;
menuMakanan[9] = "Bakso Ikan";
harga[9] = 9000;
int pilih = 0;
final String namaToko = "Kedai 46";
System.out.println(" Selamat Datang di " + namaToko);
System.out.println(" JL. Achmad Yani No. 37");
System.out.println(" Surabaya");
System.out.println("==============================");
do {
System.out.println("\nMENU KEDAI 46");
System.out.println("1. Daftar Makanan");
System.out.println("2. Cari Makanan Berdasarkan Menu");
System.out.println("3. Cari Makanan Berdasarkan Harga");
System.out.println("4. Selesai");
System.out.print("Masukkan Pilihan\t\t: ");
pilih = sc.nextInt();
switch (pilih) {
case 1:
//urutkan berdasar nama
//metode bubble sort
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 9; j++) {
if (menuMakanan[j].compareToIgnoreCase(menuMakanan[j+1]) > 0) {
String t = menuMakanan[j];
menuMakanan[j] = menuMakanan[j+1];
menuMakanan[j+1] = t;
int h = harga[j];
harga[j] = harga[j+1];
harga[j+1] = h;
}
}
}
System.out.println("DAFTAR MENU");
for (int i = 0; i < 10; i++) {
System.out.println((i + 1) + ".\t" + menuMakanan[i] + "\t" + harga[i]);
}
break;
case 2:
System.out.print("Cari Menu\t\t\t: ");
String cari = sc.next();
int idx = 0;
for (int i = 0; i < menuMakanan.length; i++) {
if (menuMakanan[i].indexOf(cari) >= 0) {
cariMakan[idx] = menuMakanan[i];
cariHarga[idx] = harga[i];
idx++;
System.out.println((idx) + ".\t" + menuMakanan[i] + "\t" + harga[i]);
}
}
//transaksi
System.out.print("Masukkan Menu\t\t\t: ");
int pilih2 = sc.nextInt();
System.out.print("Masukkan Jumlah Pesanan\t\t: ");
jumlah[jumlahBeli] = sc.nextInt();
beliMakan[jumlahBeli] = cariMakan[pilih2 - 1];
beliHarga[jumlahBeli] = cariHarga[pilih2 - 1];
subTotal[jumlahBeli] = jumlah[jumlahBeli] * beliHarga[jumlahBeli];
jumlahBeli++;
break;
case 3:
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 9; j++) {
if (harga[j] > harga[j + 1]) {
String t = menuMakanan[j];
menuMakanan[j] = menuMakanan[j + 1];
menuMakanan[j + 1] = t;
int h = harga[j];
harga[j] = harga[j + 1];
harga[j + 1] = h;
}
}
}
System.out.print("Cari Mulai Dari Harga\t\t: ");
int hargaAwal = sc.nextInt();
System.out.print("Cari Sampai Harga\t\t: ");
int hargaAkhir = sc.nextInt();
idx = 0;
for (int i = 0; i < harga.length; i++) {
if ((hargaAwal <= harga[i]) && (harga[i] <= hargaAkhir)) {
cariMakan[idx] = menuMakanan[i];
cariHarga[idx] = harga[i];
idx++;
System.out.println((idx) + ".\t" + menuMakanan[i] + "\t" + harga[i]);
}
}
//transaksi
System.out.print("Masukkan Menu\t\t\t: ");
pilih2 = sc.nextInt();
System.out.print("Masukkan Jumlah Pesanan\t\t: ");
jumlah[jumlahBeli] = sc.nextInt();
beliMakan[jumlahBeli] = cariMakan[pilih2 - 1];
beliHarga[jumlahBeli] = cariHarga[pilih2 - 1];
subTotal[jumlahBeli] = jumlah[jumlahBeli] * beliHarga[jumlahBeli];
jumlahBeli++;
break;
}
} while (pilih != 4);
//cetak daftar beli
System.out.println("=============================================");
System.out.println("Daftar Pembelian di Kedai 46");
System.out.println("---------------------------------------------");
System.out.println("No" + ".\t" + "Menu Makanan\t" + "\t" + "Harga" + "\t" + "Jumlah");
for (int i = 0; i < jumlahBeli; i++) {
if (menuMakanan[i] != null) {
System.out.println((i + 1) + ".\t" + beliMakan[i] + "\t\t" + beliHarga[i] + "\t" + jumlah[i]);
totalHarga = totalHarga + subTotal[i];
}
}
System.out.println("---------------------------------------------");
System.out.println("Tagihan\t\t\t\t\t\t: Rp " + totalHarga);
System.out.println("---------------------------------------------");
System.out.print("Tunai\t\t\t\t\t\t: Rp ");
inputUangTunai = sc.nextInt();
if (inputUangTunai == totalHarga) {
System.out.println("\t\t\t\t\t\tUANG ANDA PAS");
} else if (inputUangTunai < totalHarga) {
System.out.println("\t\t\t\t\t\tUANG ANDA KURANG");
System.out.println("Uang Kurang\t\t\t\t\t: Rp " + (totalHarga - inputUangTunai));
} else {
uangKembalian = inputUangTunai - totalHarga;
System.out.println("Kembali\t\t\t\t\t\t: Rp " + uangKembalian);
}
System.out.println("---------------------------------------------");
System.out.println(" Terima Kasih Sudah Berkunjung");
System.out.println(" di " + namaToko);
System.out.println(" Selamat Datang Kembali");
}
}
Comments
Post a Comment