Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.bahasaJava.invoice;
- import java.util.Scanner;
- import java.text.NumberFormat;
- public class InvoiceDouble{
- public static void main(String[] args){
- // Membuat objek Scanner object dan memulai while loop
- Scanner input = new Scanner(System.in);
- String pilihan = "y";
- //inisialisasi awal total invoice
- double total = 0.0;
- while (pilihan.equalsIgnoreCase("y")){
- // Memperoleh input subtotal dari user
- System.out.print("Masukkan jumlah subtotal: ");
- double subtotal = input.nextDouble();
- // Menghitung hasil
- double persentaseDiskon = 0.0;
- if (subtotal >= 100)
- persentaseDiskon = 0.1;
- else
- persentaseDiskon = 0.0;
- double jumlahDiskon = subtotal * persentaseDiskon;
- double totalSebelumPajak = subtotal - jumlahDiskon;
- double pajakPenjualan = totalSebelumPajak * 0.05;
- double totalAwal = totalSebelumPajak + pajakPenjualan;
- total += totalAwal;
- // Memformat dan menampilkan hasil
- NumberFormat currency = NumberFormat.getCurrencyInstance();
- NumberFormat percent = NumberFormat.getPercentInstance();
- String pesan = "Persentase Diskon: " + percent.format(persentaseDiskon) + "\n"
- + "Jumlah Diskon: " + currency.format(jumlahDiskon) + "\n"
- + "Total sebelum pajak: " + currency.format(totalSebelumPajak) + "\n"
- + "Pajak penjualan: " + currency.format(pajakPenjualan) + "\n"
- + "Sub total: " + currency.format(totalAwal) + "\n";
- System.out.println(pesan);
- // Memberikan pilihan apakah user akan melanjutkan atau tidak
- System.out.print("Lanjutkan? (y/n): ");
- pilihan = input.next();
- System.out.println();
- }
- //Menampilkan total invoice
- NumberFormat currency = NumberFormat.getCurrencyInstance();
- System.out.println("Total invoice adalah: " + currency.format(total));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement