0% found this document useful (0 votes)
27 views

Program Uts PDF

The document contains two Java programs. The first program calculates discounts on plastic bag purchases based on quantity. It takes user input for number of bags and outputs the total price with and without discounts applied. The second program allows a user to order food and drinks from a menu, taking input for name, item selection, and quantity and outputting the item, price per item, quantity, and total cost. Both programs demonstrate basic input/output and conditional logic in Java.

Uploaded by

Alif Bakthiar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Program Uts PDF

The document contains two Java programs. The first program calculates discounts on plastic bag purchases based on quantity. It takes user input for number of bags and outputs the total price with and without discounts applied. The second program allows a user to order food and drinks from a menu, taking input for name, item selection, and quantity and outputting the item, price per item, quantity, and total cost. Both programs demonstrate basic input/output and conditional logic in Java.

Uploaded by

Alif Bakthiar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

;

NAMA : ALIF BAKTHIAR AKBAR


NIM : 2303010123
PRODI : S1 TEKNIK KOMPUTER

PRORAM DISKON KANTONG PLASTIK

import java.text.DecimalFormat;
import java.util.Scanner;
public class versidolar {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("0.00");
System.out.print("Silakan masukkan jumlah kantong kopi yang dipesan: ");
int jumlahKantong = scanner.nextInt();
double diskon = 0;
if (jumlahKantong >= 225) {
diskon = 0.05;
} else if (jumlahKantong >= 50) {
diskon = 0.10;
} else if (jumlahKantong >= 100) {
diskon = 0.15;
} else if (jumlahKantong >= 150) {
diskon = 0.20;
} else if (jumlahKantong >= 200) {
diskon = 0.25;
} else if (jumlahKantong >= 300) {
diskon = 0.30;
}
double totalBiayaRupiah = jumlahKantong * 5.50;
double jumlahDiskonRupiah = totalBiayaRupiah * diskon;
double totalSetelahDiskonRupiah = totalBiayaRupiah - jumlahDiskonRupiah;
;

double kursDolar = 15000;


double totalBiayaDolar = totalBiayaRupiah / kursDolar;
double jumlahDiskonDolar = jumlahDiskonRupiah / kursDolar;
double totalSetelahDiskonDolar = totalSetelahDiskonRupiah / kursDolar;
System.out.println("Jumlah kantong yang dipesan: " + jumlahKantong);
System.out.println("Diskon: " + (diskon * 100) + "% - Rp"
+ df.format(jumlahDiskonRupiah) + " / $" + df.format(jumlahDiskonDolar));
System.out.println("Total biaya yang harus dibayar: Rp" + df.format(totalSetelahDiskonRupiah)
+ " / $" + df.format(totalSetelahDiskonDolar));
}
}

HASIL RUNING :
Silakan masukkan jumlah kantong kopi yang dipesan: 100
Jumlah kantong yang dipesan: 100
Diskon: 10.0% - Rp55.00 / $0.00
Total biaya yang harus dibayar: Rp495.00 / $0.03
BUILD SUCCESSFUL (total time: 10 seconds)

PROGRAM MENU MAKANAN DAN MINUMAN

import java.util.Scanner;
public class makananminuman {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int pesan;
char pilih;
String nama;
System.out.print("Masukkan nama: ");
nama = input.next();
;

System.out.println("Pilihan makanan:\n a. Nasi Goreng ($15.00)\n b. Tahu Tek


($10.00)\n c. Bakso ($13.00)\n");
System.out.println("Pilihan minuman:\n d. Es Teh ($3.00)\n e. Jus Alpukat ($12.00)\n
f. Kopi ($5.00)\n g. Air Mineral ($3.00)\n");
System.out.print("Masukkan Pilihan Makanan/Minuman: ");
pilih = input.next().charAt(0);
System.out.print("Jumlah Pesan: ");
pesan = input.nextInt();
System.out.println("================");
double totalBayar = 0;
String pesanan = "";

switch (pilih) {
case 'a':
pesanan = "Nasi Goreng";
totalBayar = pesan * 15.00;
break;
case 'b':
pesanan = "Tahu Tek";
totalBayar = pesan * 10.00;
break;
case 'c':
pesanan = "Bakso";
totalBayar = pesan * 13.00;
break;
case 'd':
pesanan = "Es Teh";
totalBayar = pesan * 3.00;
break;
case 'e':
pesanan = "Jus Alpukat";
totalBayar = pesan * 12.00;
break;
;

case 'f':
pesanan = "Kopi";
totalBayar = pesan * 5.00;
break;
case 'g':
pesanan = "Air Mineral";
totalBayar = pesan * 3.00;
break;
default:
System.out.println("Salah Pilih ! :(");
return;
}

System.out.println("Nama Pemesan: " + nama);


System.out.println("Pesanan: " + pesanan);
System.out.println("Harga: $" + totalBayar / pesan);
System.out.println("Jumlah Pesan: " + pesan);
System.out.println("Total Bayar: $" + totalBayar);
}
}

HASIL RUNING :
Masukkan nama: alif
Pilihan makanan:
a. Nasi Goreng ($15.00)
b. Tahu Tek ($10.00)
c. Bakso ($13.00)
Pilihan minuman:
d. Es Teh ($3.00)
e. Jus Alpukat ($12.00)
f. Kopi ($5.00)
g. Air Mineral ($3.00)
;

Masukkan Pilihan Makanan/Minuman: a


Jumlah Pesan: 1
================
Nama Pemesan: alif
Pesanan: Nasi Goreng
Harga: $15.0
Jumlah Pesan: 1
Total Bayar: $15.0
BUILD SUCCESSFUL (total time: 10 seconds)

You might also like