Nama : Novia Citra Fadhlilla
NPM : 22082010216
Kelas : E
Source Code :
package pengurutandata;
import java.util.Scanner;
public class PengurutanData {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String menu[] = new String[10];
int harga[] = new int[10];
int pilih = 0;
String belimenu[] = new String[5];
int beliharga[] = new int[5];
int jumlahbeli = 0;
// Inisialisasi Data
menu[0] = "Sate Ayam";
harga[0] = 13000;
menu[1] = "Sate Kambing";
harga[1] = 25000;
menu[2] = "Sate Kelopo";
harga[2] = 13000;
menu[3] = "Gulai";
harga[3] = 15000;
menu[4] = "Rawon";
harga[4] = 12000;
menu[5] = "Soto Ayam";
harga[5] = 12000;
menu[6] = "Soto Daging";
harga[6] = 12000;
menu[7] = "Rendang";
harga[7] = 15000;
menu[8] = "Kare Ayam";
harga[8] = 10000;
menu[9] = "Opor Ayam";
harga[9] = 10000;
do {
System.out.println("\n====== Selamat Datang di Warung Selera Rasa ======");
System.out.println();
System.out.println("1. Daftar Makanan");
System.out.println("2. Pencarian Harga");
System.out.println("3. Selesai");
System.out.println();
System.out.print("Pilih = ");
pilih = input.nextInt();
System.out.println();
switch (pilih) {
case 1:
// Urut Berdasarkan Nama
// 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 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("|| Daftar Makanan ||\n");
System.out.println("\tMenu\t||\tHarga\t");
System.out.println(" \t\t||\t\t ");
for (int i = 0; i < 10; i++) {
System.out.println((i + 1) + ". " + menu[i] + "\t|| Rp. " + harga[i]);
}
System.out.println();
break;
case 2:
// Pencarian Harga
System.out.print("Masukkan Minimal Harga = ");
int min = input.nextInt();
System.out.print("Masukkan Maksimal Harga = ");
int max = input.nextInt();
System.out.println();
System.out.println("|| Daftar Makanan ||\n");
System.out.println("\tMenu\t||\tHarga\t");
System.out.println(" \t\t||\t\t ");
String carimenu[] = new String[10];
int cariharga[] = new int[10];
int idx = 0;
for (int i = 0; i < 10; i++) {
if (harga[i] >= min && harga[i] <= max) {
carimenu[idx] = menu[i];
cariharga[idx] = harga[i];
idx++;
System.out.println(idx + ". " + menu[i] + "\t|| Rp. " + harga[i]);
}
}
// Transaksi
System.out.print("\nPilih menu = ");
int pilih2 = input.nextInt();
belimenu[jumlahbeli] = carimenu[pilih2 - 1];
beliharga[jumlahbeli] = cariharga[pilih2 - 1];
jumlahbeli++;
System.out.println();
break;
case 3:
System.out.println("============== Terima Kasih ==============");
break;
}
} while (pilih != 3);
// Cetak Daftar Pembelian
System.out.println("\n|| Daftar Belanja Pembeli ||\n");
System.out.println("\tMenu\t||\tHarga\t");
System.out.println(" \t\t||\t\t ");
for (int i = 0; i < jumlahbeli; i++) {
System.out.println((i + 1) + ". " + belimenu[i] + "\t|| Rp. " + beliharga[i]);
}
System.out.println();
}
}
Hasil Run :
====== Selamat Datang di Warung Selera Rasa ======
1. Daftar Makanan
2. Pencarian Harga
3. Selesai
Pilih = 1
|| Daftar Makanan ||
Menu || Harga
||
1. Gulai || Rp. 15000
2. Kare Ayam || Rp. 10000
3. Opor Ayam || Rp. 10000
4. Rawon || Rp. 12000
5. Rendang || Rp. 15000
6. Sate Ayam || Rp. 13000
7. Sate Kambing || Rp. 25000
8. Sate Kelopo || Rp. 13000
9. Soto Ayam || Rp. 12000
10. Soto Daging || Rp. 12000
====== Selamat Datang di Warung Selera Rasa ======
1. Daftar Makanan
2. Pencarian Harga
3. Selesai
Pilih = 2
Masukkan Minimal Harga = 10000
Masukkan Maksimal Harga = 25000
|| Daftar Makanan ||
Menu || Harga
||
1. Gulai || Rp. 15000
2. Kare Ayam || Rp. 10000
3. Opor Ayam || Rp. 10000
4. Rawon || Rp. 12000
5. Rendang || Rp. 15000
6. Sate Ayam || Rp. 13000
7. Sate Kambing || Rp. 25000
8. Sate Kelopo || Rp. 13000
9. Soto Ayam || Rp. 12000
10. Soto Daging || Rp. 12000
Pilih menu = 3
====== Selamat Datang di Warung Selera Rasa ======
1. Daftar Makanan
2. Pencarian Harga
3. Selesai
Pilih = 2
Masukkan Minimal Harga = 10000
Masukkan Maksimal Harga = 25000
|| Daftar Makanan ||
Menu || Harga
||
1. Gulai || Rp. 15000
2. Kare Ayam || Rp. 10000
3. Opor Ayam || Rp. 10000
4. Rawon || Rp. 12000
5. Rendang || Rp. 15000
6. Sate Ayam || Rp. 13000
7. Sate Kambing || Rp. 25000
8. Sate Kelopo || Rp. 13000
9. Soto Ayam || Rp. 12000
10. Soto Daging || Rp. 12000
Pilih menu = 10
====== Selamat Datang di Warung Selera Rasa ======
1. Daftar Makanan
2. Pencarian Harga
3. Selesai
Pilih = 3
============== Terima Kasih ==============
|| Daftar Belanja Pembeli ||
Menu || Harga
||
1. Opor Ayam || Rp. 10000
2. Soto Daging || Rp. 12000
BUILD SUCCESSFUL (total time: 33 seconds)
No comments:
Post a Comment