Pencarian data 22082010014 Risma Paramesti
package pencariandata;
import java.util.Scanner;
public class Pencariandata {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String menu[] = new String[10];
int harga[] = new int[10];
String menu_belanja[] = new String[5];
int harga_belanja[] = new int[5];
int pilih = 0, jumlah = 0;
menu [0]= "Nasi Goreng";
harga[0]= 15000;
menu [1]= "Mie Goreng";
harga[1]= 13000;
menu [2]= "Mie Ayam";
harga[2]= 10000;
menu [3]= "Ayam Geprek";
harga[3]= 17000;
menu [4]= "Ayam Bakar";
harga[4]= 21000;
do{
System.out.println("------------------------------------------------");
System.out.println(" WARUNG SEDERHANA RISMA ");
System.out.println("------------------------------------------------");
System.out.println("1. Daftar Menu ");
System.out.println("2. Filter Harga");
System.out.println("3. Selesai");
System.out.print("Pilih : ");
pilih = sc.nextInt();
System.out.println(" ");
switch(pilih){
case 1:
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 4; 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;
}
}
}
System.out.println("----------------------------------------");
System.out.println(" DAFTAR MENU ");
System.out.println("----------------------------------------");
for (int i = 0; i < 5; i++) {
System.out.println(menu[i]+" Rp"+harga[i]);
}
System.out.println(" ");
break;
case 2:
System.out.print("Masukkan Harga Minimal : ");
int min = sc.nextInt();
System.out.print("Masukkan Harga Maksimal : ");
int max = sc.nextInt();
System.out.println("-------------------------------------------");
System.out.println(" WARUNG SEDERHANA RISMA ");
System.out.println("-------------------------------------------");
System.out.println(" Menu | Harga ");
System.out.println("-------------------------------------------");
String menu_cari[] = new String[10];
int harga_cari[] = new int[10];
int idx = 0;
for (int i = 0; i <= 6; i++) {
if (harga[i] >= min && harga[i] <= max) {
menu_cari[idx] = menu[i];
harga_cari[idx] = harga[i];
idx++;
System.out.println(idx + ". " + menu[i] + " | Rp. " + harga[i]);
}
}
System.out.print("Pilih menu : ");
int pilih2 = sc.nextInt();
menu_belanja[jumlah] = menu_cari[pilih2 - 1];
harga_belanja[jumlah] = harga_cari[pilih2 - 1];
jumlah++;
System.out.println();
break;
case 3:
System.out.println("SELESAI");
System.out.println("TERIMA KASIH");
}
}while(pilih!=3);
System.out.println("-------------------------------------------");
System.out.println(" DAFTAR BELANJA ");
System.out.println("-------------------------------------------");
System.out.println(" Menu | Harga ");
System.out.println("-------------------------------------------");
for (int i = 0; i < jumlah; i++) {
System.out.println((i + 1) + ". " + menu_belanja[i] + " | Rp. " + harga_belanja[i]);
}
System.out.println();
}
}
Komentar
Posting Komentar