-
Notifications
You must be signed in to change notification settings - Fork 0
/
KafeDoWhile07.java
28 lines (27 loc) · 1.09 KB
/
KafeDoWhile07.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.Scanner;
public class KafeDoWhile07 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int kopi, teh, roti, hargaKopi = 12000, hargaTeh = 7000, hargaRoti = 20000, totalHarga;
String namaPelanggan;
do {
System.out.print("Masukkan nama pelanggan (ketik 'batal' untuk keluar): ");
namaPelanggan = sc.nextLine();
if (namaPelanggan.equalsIgnoreCase("batal")) {
System.out.println("Transaksi dibatalkan.");
break;
}
System.out.print("Jumlah kopi: ");
kopi = sc.nextInt();
System.out.print("Jumlah teh: ");
teh = sc.nextInt();
System.out.print("Jumlah roti: ");
roti = sc.nextInt();
totalHarga = (kopi * hargaKopi) + (teh * hargaTeh) + (roti * hargaRoti);
System.out.println("Total yang harus dibayar: Rp " + totalHarga);
sc.nextLine();
} while (true);
System.out.println("Semua transaksi selesai.");
sc.close();
}
}