PENCARIAN DATA
PENCARIAN DATA
NAMA: SYURAINI NOOR CHAMSYAH
NPM: 22082010033
KELAS: PARALEL A
MATA KULIAH: BAHASA PEMROGRAMAN
DOSEN PENGAMPU: NUR CAHYO WIBOWO, S.kom, M.kom.
Source code
package sortingdata;
import java.util.Scanner;
public class SortingData {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int pilih=0;
int beliharga[]= new int[5];
int pilih1=0;
int idx=0;
int total=0;
String belimenu[]=new String[5];
String menu[]={"sate", "bakso","rendang","soto","nasgor"};
int harga[]={15000,20000,13000,12000,17000};
System.out.println("SELAMAT DATANG DIWARUNG MAKAN RANI");
do{
System.out.println("=========================");
System.out.println("1.Daftar menu");
System.out.println("2.filter harga menu");
System.out.println("3.selesai");
System.out.println("=========================");
System.out.print("SILAHKAN PILIH:");
pilih= sc.nextInt();
switch(pilih){
case 1:
//urutan berdasarkan nama
for (int i = 0; i < menu.length; 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;
}
}
}
for (int i = 0; i < menu.length; i++) {
System.out.println((i+1)+". "+menu[i]+" = Rp."+harga[i]);
}
break;
case 2:
int max; int min; int no=0;
String menu1[]= new String [5];
int harga1[]= new int[5];
System.out.println("=========================");
System.out.print("masukan budget minimum: ");
System.out.print("Rp.");
min= sc.nextInt();
System.out.println("=========================");
System.out.print("masukan budget maximum: ");
System.out.print("Rp.");
max= sc.nextInt();
for (int i = 0; i < menu.length; i++) {
if(harga[i]>=min && harga[i]<=max){
menu1[no]=menu[i];
harga1[no]=harga[i];
no++;
System.out.println(no+". "+ menu[i]+ " = Rp."+harga[i]);
}
}
System.out.println("=========================");
System.out.print("silahkan pilih: ");
pilih1= sc.nextInt();
System.out.println("=========================");
belimenu[idx]=menu1[pilih1-1];
beliharga[idx]=harga1[pilih1-1];
idx++;
break;
case 3:
System.out.println("=========================");
System.out.println("Terimakasih telah memesan makanan");
System.out.println("=========================");
break;
}
}while(pilih!=3);
System.out.println("list makanan yang dibeli: ");
System.out.println("=========================");
for (int i = 0; i < idx; i++) {
System.out.println((i+1)+". "+belimenu[i]+" "+beliharga[i]);
total = total+beliharga[i];
}
System.out.println("total pembayaran menjadi =Rp. "+total);
System.out.println("===================================================");
System.out.println("TERIMAKASIH SELAMAT DATANG KEMBALI,TETAP SEHAT");
System.out.println("===================================================");
}
}
Screenshoot hasil run
Komentar
Posting Komentar