package Kuliah;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;
public class AppWarungSederhana {
static Scanner sc = new Scanner(System.in);
static int jumlah[] = new int[15];
static int strukharga[] = new int[5];
static int struk=0, grandTotal=0, uangpembeli=0, kembali=0;
static int totalbeli[] = new int [15];
static int idx = 0;
static String strukmenu[] = new String[15];
static String sellsdat [] = new String [15];
static int porsidat [] = new int [15];
static int pricedat [] = new int [15];
static int subdat [] = new int [15];
static int grandat = 0, data = 0;
static int hari = 1;
static String sellsdat1 [] = new String[15];
static int porsidat1[] = new int [15];
static String[] sort(int count, String [] menu, int [] harga){
for (int i = 0; i < count; i++) {
for (int j = 0; j < count-1; j++) {
if (menu[j].compareToIgnoreCase(menu[j+1])>0){
String t = menu [j];
menu [j] = menu [j+1];
menu [j+1] = t;
int temp1 = harga [j];
harga [j]= harga [j+1];
harga [j+1] = temp1;
}
}
}
return menu;
}
static void subtotal() {
jumlah[struk] = sc.nextInt();
totalbeli[struk]=jumlah[struk]*strukharga[struk];
grandTotal=grandTotal+totalbeli[struk];
sellsdat[data] = strukmenu[struk]; //nama makanan
porsidat[data]= jumlah[struk];// banyak porsi
subdat [data]= totalbeli[struk];
pricedat [data] = strukharga[struk];// harga perporsi
data++;
struk++;
}
static String [][] mCari(int Jmlh, String [] menu, int [] harga, String cari){
String [][] hasil = new String [10][10];
int index = 0;
for (int i = 0; i < Jmlh; i++) {
if (menu[i].indexOf(cari)>=0){
hasil [index][0] = menu [i];
hasil [index][1]= String.valueOf(harga[i]);
index++;
}
}
return hasil;
}
public static void main(String[] args) {
String makanan[] = new String [15];
int harga [] = new int [15];
int plh=0, pilihuser = 0, pilih =0;
String namamenu[] = new String[15];
int namaharga[] = new int [15];
//waktu
DateTimeFormatter formatgl = DateTimeFormatter.ofPattern("HH:mm:ss dd/MM/yyy");
LocalDateTime waktu = LocalDateTime.now();
int pilih2=0, indeks=0, idxharga=0, idxnama=0, pcs = 10;
makanan[0]="Tappoki (Original) "; harga[0]=10000;
makanan[1]="Twigim"+"\t"; harga[1]=8000;
makanan[2]="Odeng\t"; harga[2]=15000;
makanan[3]="Gimbab"; harga[3]=12000;
makanan[4]="Dakkoci";harga[4]=10000;
makanan[5]="Tappoki (Spisy) "; harga[5]=14000;
makanan[6]="Tappoki (Cheese) "; harga[6]=15000;
makanan[7]="Jajangmyeon"; harga[7]=25000;
makanan[8]="Ramyeon (Original)"; harga[8]=20000;
makanan[9]="Ramyeon (Spisy)"; harga[9]=23000;
System.out.println("\tKam's\t"+"\n Korean Street Foods");
System.out.println("=======================");
do { System.out.println("\n------- PILIH USER ------");
System.out.println("1. Kasir");
System.out.println("2. Admin");
System.out.println("3. Owner");
System.out.println("4. Exit");
System.out.print("Pilih = ");
plh = sc.nextInt();
switch(plh){
case 1: //kasir
String rangemenu[] = new String[15];
int rangeharga[] = new int[15];
do{
System.out.println("1. Buat Pesanan");
System.out.println("2. Exit");
System.out.print("Pilih = ");
pilihuser = sc.nextInt();
switch (pilihuser){
case 1 :
do{ System.out.println("\n"+"1. Daftar menu");
System.out.println("2. Pesan berdasarkan daftar menu");
System.out.println("3. Cari makanan berdasarkan nama");
System.out.println("4. Cari makanan berdasarkan harga");
System.out.println("5. Selesai");
System.out.print("pilih: ");
pilih = sc.nextInt();
switch (pilih){
case 1:
System.out.println("--------Daftar menu--------");
String[] urut = sort(pcs, makanan, harga);
for (int i = 0; i < pcs; i++) {
System.out.println((i+1)+". "+urut[i]+"\t"+harga[i]);
}
break;
case 2:
System.out.print("Pilih menu :");
pilih2=sc.nextInt();
strukmenu[struk]=makanan[pilih2-1];
strukharga[struk]=harga[pilih2-1];
System.out.print("Jumlah pesanan :");
subtotal();
break;
case 3:
System.out.print("Cari makanan :");
String cari = sc.next();
String tempmenu = sc.nextLine();
String p = cari+tempmenu;
String search [][]= mCari (pcs, makanan, harga, p);
for (int i = 0; i < pcs; i++) {
if (makanan[i].contains(p)) {
namamenu [idxnama] = makanan[i];
namaharga[idxnama] = harga[i];
idxnama++;
System.out.println(idxnama+"."+makanan[i]+"\t"+harga[i]);
}
} System.out.print("Pilih menu :");
pilih2=sc.nextInt();
strukmenu[struk]=namamenu[pilih2-1];
strukharga[struk]=namaharga[pilih2-1];
System.out.print("Jumlah pesanan :");
subtotal();
break;
case 4:
int cariharga=0;
System.out.print("Harga mulai :");
int hargaawal = sc.nextInt();
System.out.print("Sampai harga :");
int hargaakhir = sc.nextInt();
for (int i = 0; i < harga.length; i++) {
if(hargaawal <= harga[i] && harga[i]<=hargaakhir){
rangemenu[idxharga] = makanan[i];
rangeharga[idxharga] = harga[i];
idxharga++;
System.out.println(idxharga+"."+makanan[i]+"\t"+harga[i]);
}
} System.out.print("Pilih menu :");
pilih2=sc.nextInt();
strukmenu[struk]=rangemenu[pilih2-1];
strukharga[struk]=rangeharga[pilih2-1];
System.out.print("Jumlah pesanan :");
subtotal();
break;
}
}while (pilih!=5);
break;
}
System.out.println("\n----------------------- STRUK PEMBELI -----------------------");
System.out.println("\t\t\t Kam's\t"+"\n \t\t Korean Street Foods");
System.out.println("\t\t "+waktu);
System.out.println(" ");
System.out.println("No. Menu\t\tHarga\t\tJumlah\t\tTotal");
for (int i = 0; i < struk; i++) {
System.out.println((i+1)+". "+strukmenu[i]+" Rp."+strukharga[i]+"\t\t"+jumlah[i]+"\t\t Rp."+totalbeli[i]);
}
System.out.println("---------------------------------------------------------------");
System.out.println("TOTAL : Rp. " +grandTotal);
System.out.print("Bayar : Rp. ");
uangpembeli = sc.nextInt();
if (uangpembeli>grandTotal){
kembali=uangpembeli-grandTotal;
System.out.println("Kembali : Rp. " +kembali);
}
else{
System.out.println("Uang Anda PAS");
}
System.out.println("---------------------------------------------------------------");
System.out.println("kam-sa-ham-ni-da"+"\nTerimakasih :)");
//reset array
struk = 0;
grandTotal = 0;
jumlah[struk] = 0;
strukharga[struk]=0;
totalbeli[struk]= 0;
break;
}while (pilihuser!=2);//keluar dari user kasir
break; //kasir
case 2: //Admin
do{
System.out.println("\n----- HALAMAN ADMIN -----");
System.out.println("1. Tampilkan Menu");
System.out.println("2. Tambah Menu");
System.out.println("3. Hapus Menu");
System.out.println("4. Ganti Menu");
System.out.println("5. Exit");
System.out.print("Pilih = ");
pilihuser = sc.nextInt();
switch (pilihuser) {
case 1: // menu
System.out.println("-------- MENU --------");
String[] urut = sort(pcs, makanan, harga );
for (int i = 0; i < pcs; i++) {
System.out.println((i+1)+". "+urut[i]+"\t"+"["+harga[i]+"]");}
break; //menu
case 2://tambah
System.out.print("Nama = ");
makanan [pcs] = sc.next();
String tempmenu1 = sc.nextLine();
String p = makanan[pcs]+tempmenu1;
makanan [pcs] = p;
System.out.print("Harga = ");
harga [pcs]= sc.nextInt();
System.out.println("Menu "+"'"+makanan[pcs]+"'"+" berhasil ditambahkan");
pcs++;
break; //tambah
case 3://hapus
System.out.print("Nama menu = ");
String hapusmenu = sc.next();
String tempmenu2 = sc.nextLine();
String x = hapusmenu+tempmenu2;
boolean find = false;
int idkmkn = 0;
for (int i = 0; i < pcs; i++) {
if (makanan[i].compareToIgnoreCase(x) ==0 ){
find = true;
idkmkn=i;
System.out.println("Menu "+"'"+x+"'" +" berhasil dihapus");
break;
}
}
if (find==false){
System.out.println("Menu tidak ditemukan.");
} else
for (int i = idkmkn; i < pcs-1; i++) {
makanan[i]=makanan[i+1];
}
pcs--;
break; //hapus
case 4://ganti
System.out.print("Nama makanan yang diganti = ");
String namamakan = sc.next();
String tempmenu3 = sc.nextLine();
String y = namamakan+tempmenu3;
String newmenu;
int newharga;
System.out.print("Masukan nama menu baru = ");
newmenu = sc.next();
String tempmenu4 = sc.nextLine();
String z = newmenu+tempmenu4;
System.out.print("Masukan harganya = ");
newharga= sc.nextInt();
System.out.print("");
boolean ketemu = false;
int idkmenu = 0; for (int i = 0; i < pcs; i++) {
if (makanan[i].compareToIgnoreCase(y)==0){
ketemu = true;
idkmenu=i;
harga[i]=0;
makanan[i]="";
harga[i]=newharga;
makanan [i] = z;
System.out.println("Menu "+"'"+y+"'"+" diganti "+"'"+z+"'");
}
}
break; //ganti
}
} while(pilihuser!=5);
break;//admin
case 3: //owner
System.out.println("\n----- HALAMAN OWNER -----");
System.out.println("1. Total Pemasukan");
System.out.println("2. 5 Menu Terlaris");
System.out.println("3. Exit");
System.out.print("Pilih = ");
pilihuser = sc.nextInt();
switch (pilihuser) {
case 1 :
System.out.println("---------------------------------------------------------------");
System.out.println("[\t\t TOTAL PEMASUKAN\t\t]");
System.out.println("---------------------------------------------------------------");
System.out.println("Hari ke : "+hari);
System.out.println("No. Tanggal Waktu \tMenu \t Harga \t Porsi \t Subtotal");
for (int i = 0; i < data; i++) {
System.out.println((i+1)+". "+ waktu+"\t" +sellsdat[i]+"\t"+pricedat[i]+"\t"+porsidat[i]+"\t"+subdat[i]);
grandat = grandat+subdat[i];
} System.out.println("---------------------------------------------------------------");
System.out.println("Total Pemasukan \t\t : "+grandat);
System.out.println("---------------------------------------------------------------");
hari++;
data++;
break;
case 2 :
sellsdat1 = sellsdat;
porsidat1 = porsidat;
for (int i = 0; i < 4; i++) {
for (int j = i+1 ; j < 5 ; j++) {
if (porsidat1[i] < porsidat[j]) {
int temp = porsidat1[j];
porsidat1[j] = porsidat[i];
porsidat1 [i] = temp;
String top = sellsdat1[j];
sellsdat1 [j] = sellsdat [i];
sellsdat[i] = top;
}
}
}
System.out.println("---------------------------------------------------------------");
System.out.println("* TOP 5 MENU TERLARIS *");
System.out.println("---------------------------------------------------------------");
System.out.println("no. Barang \t\tporsi\t\tProfit");
for (int i = 0; i < 5; i++) {
if(sellsdat1!=null){
System.out.println((i+1)+". "+sellsdat1[i]+"\t\t"+porsidat1[i]+"\t\t"+subdat[i]);
}
}
break;
}
break; //owner
}//percabangan pilih user
} while (plh!=4); //loop awal
System.out.println("Program Selesai");
}//main
}
Pengaplikasian Method Pada Program Kasir Sederhana
Berikut adalah source code programnya :
package Kuliah;
import java.util.Scanner;
public class methodWarung {
//variabel global
Scanner sc = new Scanner (System.in);
static int harga[] = new int [10];
// static int harga[] = new int [10];
static int hitungharga(int hargasatuan, int jumlah)//header
{
//body
int harga = hargasatuan * jumlah;
return harga;
}
static String[] sort(String[] menu){
for (int i = 0; i < menu.length; i++) {
for (int j = 0; j < menu.length-1; j++) {
if(menu[j].compareToIgnoreCase(menu[j+1])>0){
String t = menu [j];
menu [j] = menu [j+1];
menu [j+1]=t;
int h = harga[j];
harga [j] = harga [j+1];
harga [j+1] = h;
}
}
}
return menu;
}
static String[] [] search(String[] menu, int harga[], String cari){
String[][] hasil = new String [10][2];
int idx = 0;
for (int i = 0; i < menu.length; i++) {
if(menu[i].indexOf(cari)>=0){
hasil[idx][0]=menu[i];
hasil[idx][1]=String.valueOf(harga[i]);
idx++;
}
}
return hasil;
}
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
String makanan []= new String[10];
String minuman []= new String [5];
String snack [] = new String [5];
int hargamaem []=new int [10];
int hargamimik []=new int [5];
int hargasnack []= new int[5];
int idx=0, idxmkn=0, idxmnm=0, idxsnk=0;
int pilih=0;
String pesanan[][]= new String[10][3];
int total [] = new int [10];
int beli;
int jumlah [] = new int [10];
int grandtotal = 0;
//inisialisasi array
minuman [0]="Es Teh "; hargamimik[0]= 3000;
minuman [1]="Es Jeruk "; hargamimik[1]= 4000;
minuman [2]="Air Putih "; hargamimik[2]= 2000;
minuman [3]="Teh Hangat "; hargamimik[3]= 4500;
minuman [4]="Jeruk Hangat "; hargamimik[4]= 5500;
makanan[0]="Sate Ayam"; hargamaem[0]=12000;
makanan[1]="Sate Sapi"; hargamaem[1]=15000;
makanan[2]="Sate Kambing"; hargamaem[2]=20000;
makanan[3]="Soto Madura"; hargamaem[3]=12000;
makanan[4]="Soto Lamongan"; hargamaem[4]=14000;
makanan[5]="Gado-Gado"; hargamaem[5]=10000;
makanan[6]="Rawon"; hargamaem[6]=13000;
makanan[7]="Bakso"; hargamaem[7]=8000;
makanan[8]="Pecel"; hargamaem[8]=7000;
makanan[9]="Penyetan"; hargamaem[9]=9000;
snack[0] = "kentang goreng"; hargasnack[0]= 10000;
snack[1] = "kerupuk "; hargasnack[1]= 2000;
snack[2] = "sosis "; hargasnack[2]= 5000;
snack[3] = "lontong "; hargasnack[3]= 2000;
snack[4] = "bakwan "; hargasnack[4]= 5000;
pilih = 0;
do {
System.out.println("MENU");
System.out.println("1. Makanan");
System.out.println("2. Minuman");
System.out.println("3. Snack");
System.out.println("4. Exit");
System.out.print("Pilih = ");
pilih = sc.nextInt();
switch(pilih){
case 1:
System.out.println("1. Daftar Makanan");
System.out.println("2. Cari Makanan");
System.out.print("Pilih = ");
int pilih2=sc.nextInt();
switch(pilih2){
case 1:
String[] urut = sort(makanan);
System.out.println("Daftar Menu");
for (int i = 0; i < 10; i++) {
System.out.println((i+1)+". "+urut[i]);
}
System.out.println("");
break;
case 2:
System.out.print("Cari = ");
String c = sc.next();
String hasilcarimaem[][]=search(makanan, hargamaem, c);
System.out.println("Hasil Pencarian");
for (int i = 0; i < hasilcarimaem.length; i++) {
if (hasilcarimaem[i][0]!=null){
System.out.print((i+1)+". "+hasilcarimaem[i][0]+" ");
System.out.println(Integer.parseInt(hasilcarimaem[i][1]));
}
}
System.out.print("Pilih = ");
beli=sc.nextInt();
System.out.print("Jumlah = ");
jumlah[idx]= sc.nextInt();
pesanan[idx][0] = hasilcarimaem[beli - 1][0];
pesanan[idx][1] = String.valueOf(hasilcarimaem[beli-1][1]);
total[idx]= hitungharga(Integer.parseInt(pesanan[idx][1]), jumlah[idx]);
idx++;
System.out.println(" ");
break;
} break;
case 2:
System.out.println("1. Daftar Minuman");
System.out.println("2. Cari Minuman");
System.out.print("Pilih = ");
pilih2=sc.nextInt();
switch(pilih2){
case 1:
String[] urut = sort(minuman);
System.out.println("Daftar Menu");
for (int i = 0; i < urut.length; i++) {
System.out.println((i+1)+". "+urut[i]);
}
System.out.println("");
break;
case 2:
System.out.print("Cari = ");
String m = sc.next();
String hasilcarimimik[][]=search(minuman, hargamimik, m);
System.out.println("Hasil Pencarian");
for (int i = 0; i < hasilcarimimik.length; i++) {
if (hasilcarimimik[i][0]!=null){
System.out.print((i+1)+". "+hasilcarimimik[i][0]+" ");
System.out.println(Integer.parseInt(hasilcarimimik[i][1]));
}
}
System.out.print("Pilih = ");
beli=sc.nextInt();
System.out.print("Jumlah = ");
jumlah[idx]= sc.nextInt();
pesanan[idx][0] = hasilcarimimik[beli - 1][0];
pesanan[idx][1] = String.valueOf(hasilcarimimik[beli-1][1]);
total[idx]= hitungharga(Integer.parseInt(pesanan[idx][1]), jumlah[idx]);
idx++;
System.out.println(" ");
break;
} break;
case 3:
System.out.println("1. Daftar Snack");
System.out.println("2. Cari Snack");
System.out.print("Pilih = ");
pilih2=sc.nextInt();
switch(pilih2){
case 1:
String[] urut = sort(snack);
System.out.println("Daftar Menu");
for (int i = 0; i < urut.length; i++) {
System.out.println((i+1)+". "+urut[i]);
}
System.out.println("");
break;
case 2:
System.out.print("Cari = ");
String s = sc.next();
String hasilcarisnack[][]=search(snack, hargasnack, s);
System.out.println("Hasil Pencarian");
for (int i = 0; i < hasilcarisnack.length; i++) {
if (hasilcarisnack[i][0]!=null){
System.out.print((i+1)+". "+hasilcarisnack[i][0]+" ");
System.out.println(Integer.parseInt(hasilcarisnack[i][1]));
}
System.out.print("Pilih = ");
beli=sc.nextInt();
System.out.print("Jumlah = ");
jumlah[idx]= sc.nextInt();
pesanan[idx][0] = hasilcarisnack[beli - 1][0];
pesanan[idx][1] = String.valueOf(hasilcarisnack[beli-1][1]);
total[idx]= hitungharga(Integer.parseInt(pesanan[idx][1]), jumlah[idx]);
idx++;
System.out.println(" ");
break;}
} break;
case 4:
System.out.println("Terima kasih...");
break;
}
}while (pilih!=4);
System.out.println("_____________________________________");
System.out.println(" DAFTAR PESANAN ");
System.out.println("_____________________________________");
System.out.println("No.Makanan\t\tHarga\tPcs\tTotal Biaya");
for (int i=0; i
Berikut adalah contoh hasil run programnya :
run:
MENU
1. Makanan
2. Minuman
3. Snack
4. Exit
Pilih = 1
1. Daftar Makanan
2. Cari Makanan
Pilih = 1
Daftar Menu
1. Bakso
2. Gado-Gado
3. Pecel
4. Penyetan
5. Rawon
6. Sate Ayam
7. Sate Kambing
8. Sate Sapi
9. Soto Lamongan
10. Soto Madura
MENU
1. Makanan
2. Minuman
3. Snack
4. Exit
Pilih = 1
1. Daftar Makanan
2. Cari Makanan
Pilih = 2
Cari = Soto
Hasil Pencarian
1. Soto Lamongan 7000
2. Soto Madura 9000
Pilih = 1
Jumlah = 2
MENU
1. Makanan
2. Minuman
3. Snack
4. Exit
Pilih = 2
1. Daftar Minuman
2. Cari Minuman
Pilih = 1
Daftar Menu
1. Air Putih
2. Es Jeruk
3. Es Teh
4. Jeruk Hangat
5. Teh Hangat
MENU
1. Makanan
2. Minuman
3. Snack
4. Exit
Pilih = 2
1. Daftar Minuman
2. Cari Minuman
Pilih = 2
Cari = Es
Hasil Pencarian
1. Es Jeruk 4000
2. Es Teh 2000
Pilih = 1
Jumlah = 2
MENU
1. Makanan
2. Minuman
3. Snack
4. Exit
Pilih = 3
1. Daftar Snack
2. Cari Snack
Pilih = 1
Daftar Menu
1. bakwan
2. kentang goreng
3. kerupuk
4. lontong
5. sosis
MENU
1. Makanan
2. Minuman
3. Snack
4. Exit
Pilih = 3
1. Daftar Snack
2. Cari Snack
Pilih = 2
Cari = sosis
Hasil Pencarian
1. sosis 5000
Pilih = 1
Jumlah = 2
MENU
1. Makanan
2. Minuman
3. Snack
4. Exit
Pilih = 4
Terima kasih...
_____________________________________
DAFTAR PESANAN
_____________________________________
No.Makanan Harga Pcs Total Biaya
1. Soto Lamongan 7000 2 14000
2. Es Jeruk 4000 2 8000
3. sosis 5000 2 10000
___________________________________
Grand Total = 32000
BUILD SUCCESSFUL (total time: 2 minutes 7 seconds)
Penerapan "Pencarian" dalam Program Kasir Warung Sederhana
package Kuliah;
import java.util.Scanner;
public class Searching {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
String menu[] = new String [10];
int harga[] = new int [10];
int pilih = 0, idx = 0, indeks=0, idxharga=0, pilih2=0, idxnama=0;
String rangemenu[] = new String[10];
int rangeharga[] = new int[10];
String namamenu[] = new String[10];
int namaharga[] = new int [10];
String strukmenu[] = new String[5];
int jumlah[] = new int[10];
int strukharga[] = new int[5];
int struk=0, grandTotal=0, uangpembeli=0, kembali=0;
int totalbeli[] = new int [10];
menu[0]="Tappoki (Original) "; harga[0]=10000;
menu[1]="Twigim "; harga[1]=8000;
menu[2]="Odeng "; harga[2]=15000;
menu[3]="Gimbab "; harga[3]=12000;
menu[4]="Dakkoci "; harga[4]=10000;
menu[5]="Tappoki (Spisy) "; harga[5]=14000;
menu[6]="Tappoki (Cheese) "; harga[6]=15000;
menu[7]="Jajangmyeon "; harga[7]=25000;
menu[8]="Ramyeon (Original)"; harga[8]=20000;
menu[9]="Ramyeon (Spisy) "; harga[9]=23000;
System.out.println("\tKams\t"+"\n Korean Street Foods");
System.out.println("=======================");
do{
System.out.println("\n"+"1. Daftar menu");
System.out.println("2. Cari makanan berdasarkan nama");
System.out.println("3. Cari makanan berdasarkan harga");
System.out.println("4. Selesai");
System.out.print("pilih: ");
pilih = sc.nextInt();
switch(pilih){
case 1 : System.out.println("--------Daftar menu--------"); //bubble sort
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 9; j++) {
if(menu[j].compareToIgnoreCase(menu[j+1])>0){
String temp=menu[j];
menu[j]=menu[j+1];
menu[j+1]=temp;
int h=harga[j];
harga[j]=harga[j+1];
harga[j+1]=h;
}
}
}
for (int i = 0; i < 10; i++) {
System.out.println(menu[i]+" "+"\t"+harga[i]);
}
break;
case 2 : System.out.print("Cari makanan :");
String cari = sc.next();
for (int i = 0; i < menu.length; i++) {
if (menu[i].contains(cari)) {
namamenu [idxnama] = menu[i];
namaharga[idxnama] = harga[i];
idxnama++;
System.out.println(idxnama+"."+menu[i]+"\t"+harga[i]);
}
}
System.out.print("Pilih menu :");
pilih2=sc.nextInt();
strukmenu[struk]=namamenu[pilih2-1];
strukharga[struk]=namaharga[pilih2-1];
System.out.print("Jumlah pesanan :");
jumlah[struk] = sc.nextInt();
totalbeli[struk]=jumlah[struk]*strukharga[struk];
grandTotal=grandTotal+totalbeli[struk];
struk++;
break;
case 3 : int cariharga=0;
System.out.print("Harga mulai :");
int hargaawal = sc.nextInt();
System.out.print("Sampai harga :");
int hargaakhir = sc.nextInt();
for (int i = 0; i < harga.length; i++) {
if(hargaawal <= harga[i] && harga[i]<=hargaakhir){
rangemenu[idxharga] = menu[i];
rangeharga[idxharga] = harga[i];
idxharga++;
System.out.println(idxharga+"."+menu[i]+"\t"+harga[i]);
}
}
System.out.print("Pilih menu :");
pilih2=sc.nextInt();
strukmenu[struk]=rangemenu[pilih2-1];
strukharga[struk]=rangeharga[pilih2-1];
System.out.print("Jumlah pesanan :");
jumlah[struk] = sc.nextInt();
totalbeli[struk]=jumlah[struk]*strukharga[struk];
grandTotal=grandTotal+totalbeli[struk];
struk++;
break;
case 4 : System.out.println("Terimakasih...");
break;
}
}while(pilih!=4);
System.out.println("------------------STRUK PEMBELI------------------");
System.out.println("No. Menu\t\tHarga\t\tJumlah\t\tTotal");
for (int i = 0; i < struk; i++) {
System.out.println((i+1)+". "+strukmenu[i]+" Rp."+strukharga[i]+"\t\t"+jumlah[i]+"\t\t Rp."+totalbeli[i]);
}
System.out.println("--------------------------------------------------");
System.out.println("TOTAL : Rp. " +grandTotal);
System.out.print("Bayar : Rp. ");
uangpembeli = sc.nextInt();
if (uangpembeli>grandTotal){
kembali=uangpembeli-grandTotal;
System.out.println("Kembali : Rp. " +kembali);
}
else{
System.out.println("Uang Anda PAS");
}
System.out.println("--------------------------------------------------");
System.out.println("kam-sa-ham-ni-da"+"\nTerimakasih :)");
}
}
Dan berikut adalah contoh hasil running programnya :
run:
Kams
Korean Street Foods
=======================
1. Daftar menu
2. Cari makanan berdasarkan nama
3. Cari makanan berdasarkan harga
4. Selesai
pilih: 1
--------Daftar menu--------
Dakkoci 10000
Gimbab 12000
Jajangmyeon 25000
Odeng 15000
Ramyeon (Original) 20000
Ramyeon (Spisy) 23000
Tappoki (Cheese) 15000
Tappoki (Original) 10000
Tappoki (Spisy) 14000
Twigim 8000
1. Daftar menu
2. Cari makanan berdasarkan nama
3. Cari makanan berdasarkan harga
4. Selesai
pilih: 2
Cari makanan :Tappoki
1.Tappoki (Cheese) 15000
2.Tappoki (Original) 10000
3.Tappoki (Spisy) 14000
Pilih menu :1
Jumlah pesanan :2
1. Daftar menu
2. Cari makanan berdasarkan nama
3. Cari makanan berdasarkan harga
4. Selesai
pilih: 3
Harga mulai :10000
Sampai harga :15000
1.Dakkoci 10000
2.Gimbab 12000
3.Odeng 15000
4.Tappoki (Cheese) 15000
5.Tappoki (Original) 10000
6.Tappoki (Spisy) 14000
Pilih menu :3
Jumlah pesanan :1
1. Daftar menu
2. Cari makanan berdasarkan nama
3. Cari makanan berdasarkan harga
4. Selesai
pilih: 4
Terimakasih...
------------------STRUK PEMBELI-------------------------
No. Menu Harga Jumlah Total
1. Tappoki (Cheese) Rp.15000 2 Rp.30000
2. Odeng Rp.15000 1 Rp.15000
--------------------------------------------------------
TOTAL : Rp. 45000
Bayar : Rp. 50000
Kembali : Rp. 5000
---------------------
kam-sa-ham-ni-da
Terimakasih :)
BUILD SUCCESSFUL (total time: 38 seconds)
Yanuar Hakam Rosyadi Ahamad
21082010079
Berikut adalah source code nya :
import java.util.Scanner;
public class sort {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String menu[] = new String[5];
int harga[] = new int[5];
int pilih = 0, pesan = 0;
System.out.println("\tKam's\t"+"\nKorean Street Foods");
do {
menu [0] = "Dakkoci"; harga [0] = 11000;
menu [1] = "Twigim "; harga [1] = 8000;
menu [2] = "Tappoki"; harga [2] = 10000;
menu [3] = "Gimbab "; harga [3] = 12000;
menu [4] = "Odeng "; harga [4] = 15000;
System.out.println("Ingin Memesan? ");
System.out.println("1. Ya");
System.out.println("2. Tidak");
System.out.print("Pilih : ");
pesan = sc.nextInt();
if (pesan ==1){
do{
System.out.println("Pilihan Kategori");
System.out.println("1. Daftar Menu Makanan");
System.out.println("2. Urutan Makanan dari Harga Termahal");
System.out.println("3. Urutan Makanan dari Harga Termurah");
System.out.println("4. Selesai");
System.out.print("Pilih : ");
pilih = sc.nextInt();
switch(pilih){
case 1:
System.out.println("Daftar Menu Makanan");
System.out.println("No Menu\t\t\tHarga");
for (int i = 0; i < 5; i++){
System.out.println((i + 1) + ". "+menu[i]+"\t"+harga[i]);
}
break;
case 2 :
String menu2[] = new String[5];
menu2 = menu;
int harga2[] = new int[5];
harga2 = harga; //bubblesort
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 4; j++) {
if(harga2[j] < harga2[j+1]){
int temp = harga2[j];
harga2[j] = harga2[j+1];
harga2[j+1] = temp;
String temp2 = menu2[j];
menu2[j] = menu[j+1];
menu2[j+1] = temp2;
}
}
}
System.out.println("");
System.out.println("\tUrutan Menu Termahal\t");
System.out.println("No Menu\tHarga");
for (int i = 0; i < 5; i++) {
System.out.println((i + 1) + ". "+menu2[i]+"\t"+harga2[i]);
}
break;
case 3 :
menu2 = menu;
harga2=harga; //bubblesort
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 4; j++) {
if(harga2[j] > harga2[j+1]){
int temp = harga2[j];
harga2[j] = harga2[j+1];
harga2[j+1]= temp;
String temp2 = menu2[j];
menu2[j] = menu[j+1];
menu2[j+1] = temp2;
}
}
}
System.out.println("");
System.out.println("\tUrutan Menu Termurah\t");
System.out.println("No Menu\tHarga");
for (int i = 0; i < 5; i++) {
System.out.println((i + 1) + ". "+ menu2[i]+"\t"+harga2[i]);
}
break;
case 4 :
System.out.println("Selesai");
break;
}
} while (pilih!=4);
}} while (pesan!=2);
System.out.println("=======================");
System.out.println("kam-sa-ham-ni-da"+"\nTerimakasih :)");
System.out.println("=======================");
}
}
Dan berikut adalah hasil running programnya :
run:
Kam's
Korean Street Foods
Ingin Memesan?
1. Ya
2. Tidak
Pilih : 1
Pilihan Kategori
1. Daftar Menu Makanan
2. Urutan Makanan dari Harga Termahal
3. Urutan Makanan dari Harga Termurah
4. Selesai
Pilih : 2
Urutan Menu Termahal
No Menu Harga
1. Odeng 15000
2. Gimbab 12000
3. Dakkoci 11000
4. Tappoki 10000
5. Twigim 8000
Pilihan Kategori
1. Daftar Menu Makanan
2. Urutan Makanan dari Harga Termahal
3. Urutan Makanan dari Harga Termurah
4. Selesai
Pilih : 3
Urutan Menu Termurah
No Menu Harga
1. Twigim 8000
2. Tappoki 10000
3. Dakkoci 11000
4. Gimbab 12000
5. Odeng 15000
Pilihan Kategori
1. Daftar Menu Makanan
2. Urutan Makanan dari Harga Termahal
3. Urutan Makanan dari Harga Termurah
4. Selesai
Pilih : 4
Selesai
Ingin Memesan?
1. Ya
2. Tidak
Pilih : 2
=======================
kam-sa-ham-ni-da
Terimakasih :)
=======================
BUILD SUCCESSFUL (total time: 16 seconds)
Yanuar Hakam Rosyadi Ahmad (21082010079)
Berikut adalah source code-nya :
package Collage;
import java.util.Scanner;
public class array2dimensi {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
String pesanan[][] = new String[5][2];
int idx = 0, makanan = 0, minuman = 0;
int nominal[][] = new int [5][6];
int pesan = 0, pilih1 = 0, pilih2 = 0, jumlah = 0, Total = 0;
do{
System.out.println("Ingin Memesan?");
System.out.println("1. Ya");
System.out.println("2. Tidak");
System.out.print("Pilih : ");
pesan = sc.nextInt();
if (pesan==1){
do{
System.out.println("=====================");
System.out.println("\tKams\t"+"\n Korean Street Foods");
System.out.println("Pilihan Menu : ");
System.out.println("1. Makanan");
System.out.println("2. Minuman");
System.out.println("3. Selesai");
System.out.print("Pilih : ");
pilih1 = sc.nextInt();
switch (pilih1){
case 1 :
System.out.println("----------------------");
System.out.println("Daftar Makanan : ");
System.out.println("1. Odeng");
System.out.println("2. Toppoki");
System.out.println("3. Gimbab");
System.out.print("Pilih : ");
pilih2 = sc.nextInt();
switch (pilih2){
case 1 :
pesanan[makanan][0] = "Odeng";
nominal[makanan][0] = 15000;
break;
case 2 :
pesanan[makanan][0] = "Toppoki";
nominal[makanan][0] = 10000;
break;
case 3 :
pesanan[makanan][0] = "Gimbab";
nominal[makanan][0] = 12000;
break;
}
System.out.print("Jumlah : ");
jumlah = sc.nextInt();
nominal[makanan][2] = jumlah;
nominal[makanan][4] = nominal[makanan][0] * nominal[makanan][2];
makanan++;
break;
case 2 :
System.out.println("----------------------");
System.out.println("Daftar Minuman : ");
System.out.println("1. Bubble Tea");
System.out.println("2. Lemon Tea");
System.out.println("3. Air Mineral");
System.out.print("Pilih : ");
pilih2 = sc.nextInt();
switch (pilih2){
case 1 :
pesanan[minuman][1] = "Bubble Tea";
nominal[minuman][1] = 1500;
break;
case 2 :
pesanan[minuman][1] = "Lemon Tea";
nominal[minuman][1] = 5000;
break;
case 3 :
pesanan[minuman][1] = "Air Mineral";
nominal[minuman][1] = 3000;
break;
}
System.out.print("Jumlah : ");
jumlah = sc.nextInt();
nominal[minuman][3] = jumlah;
nominal[minuman][5] = nominal[minuman][1] * nominal[minuman][3];
minuman++;
break;
case 3 :
System.out.println("");
}
idx++;
}while(pilih1!=3 && makanan!=5 && minuman!=5);
System.out.println("--------------Daftar Pembelian---------------");
System.out.println("Makanan"+"\t"+"\t"+"Harga"+"\t"+"Jumlah"+"\t"+"Total");
for(int i = 0; i < 5; i++){
if(pesanan[i][0]!=null){
System.out.print("\n"+(i+1)+"."+pesanan[i][0]);
System.out.print("\t"+nominal[i][0]);
System.out.print("\t"+nominal[i][2]);
System.out.print("\t"+nominal[i][4]);
Total = Total + nominal[i][4];
}
}
System.out.println(" ");
System.out.println("\nMinuman"+"\t"+"\t"+"Harga"+"\t"+"Jumlah"+"\t"+"Total");
for(int n = 0; n < 5; n++){
if(pesanan[n][1]!=null){
System.out.print("\n"+(n+1)+"."+pesanan[n][1]);
System.out.print("\t"+nominal[n][1]);
System.out.print("\t"+nominal[n][3]);
System.out.print("\t"+nominal[n][5]);
Total = Total + nominal[n][5];
}
}
System.out.println("\n--------------------------------------------");
System.out.println("Total Harga : Rp "+Total);
System.out.println("-----------------Terimakasih----------------");
}
}while(pesan!=2);
System.out.println("");
System.out.println("kam-sa-ham-ni-da"+"\nTerimakasih :)");
}
}
Dan berikut adalah hasil running programnya :
run:
Ingin Memesan?
1. Ya
2. Tidak
Pilih : 1
=====================
Kams
Korean Street Foods
Pilihan Menu :
1. Makanan
2. Minuman
3. Selesai
Pilih : 1
----------------------
Daftar Makanan :
1. Odeng
2. Toppoki
3. Gimbab
Pilih : 1
Jumlah : 2
=====================
Kams
Korean Street Foods
Pilihan Menu :
1. Makanan
2. Minuman
3. Selesai
Pilih : 1
----------------------
Daftar Makanan :
1. Odeng
2. Toppoki
3. Gimbab
Pilih : 2
Jumlah : 2
=====================
Kams
Korean Street Foods
Pilihan Menu :
1. Makanan
2. Minuman
3. Selesai
Pilih : 2
----------------------
Daftar Minuman :
1. Bubble Tea
2. Lemon Tea
3. Air Mineral
Pilih : 1
Jumlah : 1
=====================
Kams
Korean Street Foods
Pilihan Menu :
1. Makanan
2. Minuman
3. Selesai
Pilih : 2
----------------------
Daftar Minuman :
1. Bubble Tea
2. Lemon Tea
3. Air Mineral
Pilih : 2
Jumlah : 2
=====================
Kams
Korean Street Foods
Pilihan Menu :
1. Makanan
2. Minuman
3. Selesai
Pilih : 2
----------------------
Daftar Minuman :
1. Bubble Tea
2. Lemon Tea
3. Air Mineral
Pilih : 3
Jumlah : 3
=====================
Kams
Korean Street Foods
Pilihan Menu :
1. Makanan
2. Minuman
3. Selesai
Pilih : 3
--------------Daftar Pembelian---------------
Makanan Harga Jumlah Total
1.Odeng 15000 2 30000
2.Toppoki 10000 2 20000
Minuman Harga Jumlah Total
1.Bubble Tea 1500 1 1500
2.Lemon Tea 5000 2 10000
3.Air Mineral 3000 3 9000
--------------------------------------------
Total Harga : Rp 70.500,-
-----------------Terimakasih----------------
Ingin Memesan?
1. Ya
2. Tidak
Pilih : 1
=====================
Kams
Korean Street Foods
Pilihan Menu :
1. Makanan
2. Minuman
3. Selesai
Pilih : 2
----------------------
Daftar Minuman :
1. Bubble Tea
2. Lemon Tea
3. Air Mineral
Pilih : 2
Jumlah : 2
=====================
Kams
Korean Street Foods
Pilihan Menu :
1. Makanan
2. Minuman
3. Selesai
Pilih : 1
----------------------
Daftar Makanan :
1. Odeng
2. Toppoki
3. Gimbab
Pilih : 3
Jumlah : 2
=====================
Kams
Korean Street Foods
Pilihan Menu :
1. Makanan
2. Minuman
3. Selesai
Pilih : 3
--------------Daftar Pembelian---------------
Makanan Harga Jumlah Total
1.Odeng 15000 2 30000
2.Toppoki 10000 2 20000
3.Gimbab 12000 2 24000
Minuman Harga Jumlah Total
1.Bubble Tea 1500 1 1500
2.Lemon Tea 5000 2 10000
3.Air Mineral 3000 3 9000
4.Lemon Tea 5000 2 10000
--------------------------------------------
Total Harga : Rp 175.000,-
-----------------Terimakasih----------------
Ingin Memesan?
1. Ya
2. Tidak
Pilih : 2
kam-sa-ham-ni-da
Terimakasih :)
BUILD SUCCESSFUL (total time: 1 minute 9 seconds)