/*
    CalcDiscount3.java
    CIS 160
    David G. Klick
    2004-09-15

    Demonstrates more compact double-branch selection.
*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.text.DecimalFormat;

public class CalcDiscount3 {
    public static void main(String[] args) 
        throws IOException {
        String id, strIn;
        int qty;
        double price, total, subtot, discAmt, discount;
        BufferedReader kbd = new BufferedReader(
            new InputStreamReader(System.in));
        DecimalFormat currency = new DecimalFormat("     ##,##0.00");
        int len;
        String output;

        System.out.println("This program will calculate"
            + " volume discounts");

        System.out.print("Enter the item ID: ");
        id = kbd.readLine();

        System.out.print("Enter the price: ");
        price = Double.parseDouble(kbd.readLine());

        System.out.print("Enter the quantity: ");
        strIn = kbd.readLine();
        qty = Integer.parseInt(strIn);

        discount = 0;
        if (qty >= 1000) {
            discount = .2;
        } else {
            if (qty >= 144) {
                discount = .1;
            }
        }
        subtot = qty * price;
        discAmt = subtot * discount;
        total = subtot - discAmt;
        System.out.println();

        output = currency.format(subtot);
        len = output.length();
        output = output.substring(len-9);
        System.out.println("Subtotal:  " + output);

        output = currency.format(discAmt);
        len = output.length();
        output = output.substring(len-9);
        System.out.println("Discount:  " + output);

        System.out.println("           ---------");

        output = currency.format(total);
        len = output.length();
        output = output.substring(len-9);
        System.out.println("Total:     " + output);
    }
}