Skip to content

Instantly share code, notes, and snippets.

@mkdika
Created November 25, 2017 07:50
Show Gist options
  • Save mkdika/6b42fa9512bfceb264bfb31f3995cbbf to your computer and use it in GitHub Desktop.
Save mkdika/6b42fa9512bfceb264bfb31f3995cbbf to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class MikeCoffee {
static String member, pengorder;
static Order[] orders;
public static void main(String[] args) {
Scanner entry = new Scanner(System.in);
System.out.print("Apakah Member (y/n)? ");
member = entry.nextLine();
System.out.print("Nama Pengorder: ");
entry = new Scanner(System.in);
pengorder = entry.nextLine();
System.out.print("Berapa Item: ");
entry = new Scanner(System.in);
int x = entry.nextInt();
orders = new Order[x];
System.out.println();
for (int i = 0; i < orders.length; i++) {
orders[i] = new Order();
System.out.println("Minuman-" + (i + 1));
System.out.println("Pelihan Menu: ");
System.out.println("1. Americano");
System.out.println("2. Long Black");
System.out.println("3. Frappucino");
System.out.println("4. Cappuccino");
System.out.print("Pilihan Anda? ");
entry = new Scanner(System.in);
int n = entry.nextInt();
if (n == 1) {
orders[i].minuman = "Americano";
} else if (n == 2) {
orders[i].minuman = "Long Black";
} else if (n == 3) {
orders[i].minuman = "Frappucino";
} else if (n == 4) {
orders[i].minuman = "Cappuccino";
}
System.out.print("Ukuran (S/M/L)? ");
entry = new Scanner(System.in);
orders[i].ukuran = entry.nextLine();
double pricelist = 0;
if (n == 1) {
switch (orders[i].ukuran) {
case "S":
pricelist = 11000;
break;
case "M":
pricelist = 14000;
break;
case "L":
pricelist = 17000;
break;
}
} else if (n == 2) {
switch (orders[i].ukuran) {
case "S":
pricelist = 12000;
break;
case "M":
pricelist = 15000;
break;
case "L":
pricelist = 18000;
break;
}
} else if (n == 3) {
switch (orders[i].ukuran) {
case "S":
pricelist = 21000;
break;
case "M":
pricelist = 24000;
break;
case "L":
pricelist = 27000;
break;
}
} else if (n == 4) {
switch (orders[i].ukuran) {
case "S":
pricelist = 22000;
break;
case "M":
pricelist = 25000;
break;
case "L":
pricelist = 28000;
break;
}
}
if (member.equalsIgnoreCase("y")) {
pricelist = 0.85 * pricelist;
}
orders[i].harga = pricelist;
System.out.printf("Minuman: %s, Size: %s, Harga Rp. %,.2f %n",
orders[i].minuman,
orders[i].ukuran,
orders[i].harga);
System.out.println();
}
boolean b = false;
do {
System.out.println();
System.out.println("PILIHAN Menu");
System.out.println("1. Urut berdasarkan Minuman");
System.out.println("2. Urut berdasarkan Harga");
System.out.print("Pilihan Anda? ");
entry = new Scanner(System.in);
int n = entry.nextInt();
print(n);
System.out.print("Apakah mau ulang (y/n)? ");
entry = new Scanner(System.in);
String u = entry.nextLine();
if (u.equalsIgnoreCase("y")) {
b = true;
} else {
b = false;
}
} while (b);
System.out.println("BYE BYE!!!");
}
static void print(int n) {
System.out.println();
if (n == 1) {
System.out.println("MIKE COFFEE - DAFTAR ORDER (Urut Minuman)");
bsortMinuman(orders);
} else if (n == 2) {
System.out.println("MIKE COFFEE - DAFTAR ORDER (Urut Harga)");
bsortHarga(orders);
}
if (member.equalsIgnoreCase("y")) {
System.out.println("Member\t: YES");
} else {
System.out.println("Member\t: NO");
}
System.out.println("Nama\t: " + pengorder);
double totalHarga = 0;
System.out.println("==================================================");
System.out.println("Minuman \t\t Size \t Total Harga (RP)");
System.out.println("==================================================");
for (int i = 0; i < orders.length; i++) {
System.out.printf("%s \t\t %s \t %,.2f %n",
orders[i].minuman,
orders[i].ukuran,
orders[i].harga);
totalHarga += orders[i].harga;
}
System.out.println("==================================================");
System.out.printf("TOTAL HARGA \t\t\t %,.2f %n", totalHarga);
double ppn = 0.1 * totalHarga;
System.out.printf("PPN \t\t\t\t %,.2f %n", ppn);
System.out.printf("TOTAL KESELURUHAN \t\t %,.2f %n", (totalHarga + ppn));
System.out.println("JUMLAH ITEM: " + orders.length);
System.out.println();
}
static Order[] bsortMinuman(Order[] arrs) {
Order temp;
for (int i = 0; i < arrs.length - 1; i++) {
for (int j = 0; j < arrs.length - 1; j++) {
if (arrs[j].minuman.compareTo(arrs[j + 1].minuman) > 0) {
temp = arrs[j];
arrs[j] = arrs[j + 1];
arrs[j + 1] = temp;
}
}
}
return arrs;
}
static Order[] bsortHarga(Order[] arrs) {
Order temp;
for (int i = 0; i < arrs.length - 1; i++) {
for (int j = 0; j < arrs.length - 1; j++) {
if (arrs[j].harga > arrs[j + 1].harga) {
temp = arrs[j];
arrs[j] = arrs[j + 1];
arrs[j + 1] = temp;
}
}
}
return arrs;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment