Public feed #726179

Miscellany

public text v1 · immutable
Raw Edit
·published 2007-10-04 22:55 UTC
rendered paste body
//////////////////////////////////////////////////////////////////////////////////
// ICS 3M1 - Mrs. Shanks
// Patrick Paskaris
// September 21, 2007
// Invoice
// 
// This program will take as input a name, full street address, city and province
// postal code, # of CDs, and # of DVDs from a file.  It will then calculate the
// subtotal of CDs, subtotal of DVDs, subtotal of CDs and DVDs, GST, PST and the
// final total and will output an invoice displaying the company name, shipping
// information, subtotal of CDs and DVDs, the amount ordered and their individual
// costs, their subtotal before taxes, the tax amount, and the final total.
//////////////////////////////////////////////////////////////////////////////////
// Variables Used:
// amountGST - GST of subTotal
// amountPST - PST of subTotal
// br - File input
// BRAKDOWN_SP - Output spaces for breakdown
// CD_COST - Cost of CDs
// cdSubTotal - Total price of CDs
// city - City
// COST_SP - Output spaces for cost
// CURRENY - Currency symbol ($)
// DVD_COST - Cost of DVDs
// dvdSubTotal - Total price of DVDs
// fr - File Reader
// GST - GST percentage
// MULT_STR - " x "
// name - Name 
// numberOfCDs - Amount of CDs the user is buying
// numberOfDVDs - Amount of DVDs the user is buying
// postalCode - Postal code 
// PRODUCT_SP - Output spaces for product
// PRODUCT1 - Name of the first product being sold
// PRODUCT2 - Name of the second product being sold
// province - Province 
// PST - PST percentage
// STORE_NAME - Name of the store
// streetAddress - Address 
// subTotal - Total cost before taxes of order
// SUBTOTAL_SP - Output spaces for subtotal
// SUBTOTAL_STR - "SUBTOTAL"
// TAX_SP - Output spaces for taxes
// TAX1 - Name of the first tax
// TAX2 - Name of the second tax
// temp - Temporary value for input
// TITLE_SP - Output spaces for title
// TOTAL_SP - Output spaces for total
// TOTAL_STR - "TOTAL"
// totalFinal - Total cost after taxes
// UNDERLINE_SP - Output spaces for underline
// UNDERLINE_STR - "________"
//////////////////////////////////////////////////////////////////////////////////

import java.io.*;

class Invoice {
  
  public static void main ( String args[] ) throws java.io.IOException {
    
    FileReader fr = new FileReader( "in.txt" );
    BufferedReader br = new BufferedReader( fr );
    
    // Variables
    String name = "", streetAddress = "", city = "",  province = "",
      postalCode = "", temp = "";
    int numberOfCDs = 0, numberOfDVDs = 0;
    double cdSubTotal = 0, dvdSubTotal = 0, subTotal = 0, amountGST = 0, 
      amountPST = 0, totalFinal = 0;
    final double CD_COST = 16.99, DVD_COST = 24.99, GST = .06, PST = .08;
    final String STORE_NAME = "ABC MUSIC STORE", PRODUCT1 = "CDs",
      PRODUCT2 = "DVDs", TAX1 = "GST", TAX2 = "PST",  TITLE_SP = "\t\t\t", 
      PRODUCT_SP = "\t\t\t\t", BREAKDOWN_SP = "\t\t\t\t", COST_SP = "\t\t",
      UNDERLINE_SP = "\t\t\t\t\t\t", TAX_SP = "\t\t\t\t", SUBTOTAL_SP = "\t\t\t\t",
      TOTAL_SP = "\t\t\t\t", CURRENY = "$", TOTAL_STR = "TOTAL",
      SUBTOTAL_STR = "SUBTOTAL", UNDERLINE_STR = "________", MULT_STR = " x ";
    
    // Get information
    name = br.readLine( );
    streetAddress = br.readLine( );
    city = br.readLine( );
    province = br.readLine( );
    postalCode = br.readLine( );
    temp = br.readLine( );
    numberOfCDs = Integer.parseInt( temp );
    temp = br.readLine( );
    numberOfDVDs = Integer.parseInt( temp );
    temp = null; // Release
    fr.close( );
    
    // Calculate
    cdSubTotal = CD_COST * numberOfCDs;
    dvdSubTotal = DVD_COST * numberOfDVDs;
    subTotal = cdSubTotal + dvdSubTotal;
    amountGST = subTotal * GST;
    amountPST = subTotal * PST;
    totalFinal = subTotal + amountGST + amountPST;
    
    // Round it for output
    cdSubTotal = Math.round( cdSubTotal * 100 );
    cdSubTotal /= 100;
    dvdSubTotal = Math.round( dvdSubTotal * 100 );
    dvdSubTotal /= 100;
    subTotal = Math.round( subTotal * 100 );
    subTotal /= 100;
    amountGST = Math.round( amountGST * 100 );
    amountGST /= 100;
    amountPST = Math.round( amountPST * 100 );
    amountPST /= 100;
    totalFinal = Math.round( totalFinal * 100 );
    totalFinal /= 100;
    
    // Output invoice
    System.out.println( "\n\n" + TITLE_SP + STORE_NAME + "\n" );
    System.out.println( name );
    System.out.println( streetAddress );
    System.out.println( city + ", " + province );
    System.out.println( postalCode );
    System.out.println( "\n" + PRODUCT_SP + PRODUCT1 );
    System.out.println( BREAKDOWN_SP + numberOfCDs + MULT_STR + CD_COST + COST_SP +
                       CURRENY +  " " + cdSubTotal );
    System.out.println( "\n" + PRODUCT_SP + PRODUCT2 );
    System.out.println( BREAKDOWN_SP + numberOfDVDs + MULT_STR + DVD_COST +
                       COST_SP + CURRENY + " " + dvdSubTotal );
    System.out.println( UNDERLINE_SP + UNDERLINE_STR );
    System.out.println( "\n" + SUBTOTAL_SP + SUBTOTAL_STR + COST_SP + CURRENY +
                       " " + subTotal );
    System.out.println( TAX_SP + TAX1 + COST_SP + CURRENY + " " + amountGST );
    System.out.println( TAX_SP + TAX2 + COST_SP + CURRENY + " " + amountPST );
    System.out.println( UNDERLINE_SP + UNDERLINE_STR );
    System.out.println( "\n" + TOTAL_SP + TOTAL_STR + COST_SP + CURRENY + " " + 
                       totalFinal );
    
  }
  
}