/**
 *  Name: Josh Sikorski
 *  Course: CSCI 241 - Computer Science I
 *  Section: 002
 *  Assignment: 1
 *
 *  Project/Class Description
 *      The Cashier keeps track of purchases at the local Dollar
 *      Store.  All items at the same store cost the same amount;
 *      an even dollar amount which may range from $1 up to $100.
 *      Shoppers continue to pay the cashier until enough is entered,
 *      then they may complete their purchase and possibly receive
 *      change.
 *
 *  Known Bugs:
 *      none.
 */

public class Cashier
{
    // instance variables
    private int cost; // the cost of the item
    private int soFar; // the amount collected so far
    private int sum; // the total collected by the cashier
    
    /**
     * Constructor for objects of class Cashier
     * Create a cashier to run the register
     */
    public Cashier(int dollarAmount)
    {
        cost = dollarAmount;
        soFar = 0;
        sum = 0;
    }
    
    // instance methods
    
    /**
     * Return the cost of an item at the store
     * 
     * @return cost of an item from this store
     */
    public int getCost()
    {
        return cost;
    }
    
    /** 
     * Return the amount entered by the shopper so far
     * 
     * @return the amount the shopper has gathered for payment
     */
    public int getSoFar()
    {
        return soFar;
    }
    
    /** 
     * Return the sum needed to purchase all the shopper's items
     * 
     * @return the sum of the shopper's purchases
     */
    public int getSum()
    {
        return sum;
    }
    
    /**
     * Collect money from shopper
     * 
     * @param dollars money shopper gives cashier
     */
    public void collectDollars(int dollars)
    {
        if (dollars > 0) {
            soFar = soFar + dollars;
            System.out.println("Cashier received $" + dollars + ".");
        }
        else {
            System.out.println
            ("Error: Please re-enter positive dollar amount.");
        }
    }
    
    /** 
     * Print a receipt if enough money has been collected
     */
    public void printReceipt()
    {
        if (soFar >= cost) {
            // Print the receipt
            System.out.println("*********************************");
            System.out.println("* Total Purchases: $" + cost);
            System.out.println("*");
            System.out.println("* Thank you for shopping at your ");
            System.out.println("* local Dollar Store.");
            System.out.println("*********************************");
            
            // Update the shopper and cash registers amounts
            sum = sum + cost;
            soFar = soFar - cost;
        }
        else {
            // Tell shopper they are out of money
            System.out.println("Error: Insufficient amount.");
            System.out.println("Please enter an additional $" 
            + (cost - soFar) + ".");
        }
    }
    
    /**
     * Print amount overpaid
     */
    public void refundExtra()
    {
        int extra = soFar;
        soFar = 0;
        System.out.println
            ("Amount to refund: $" + extra + ".");
    }
    
    /**
     * main() method
     * 
     * Creates a Cashier object, and tests each of this class's
     * methods on it.
     */
    public static void main (String [] args)
    {
        // Create a Cashier object
        // At this store, every item costs $25
        Cashier chris = new Cashier(25);
        
        // First shopper gives cashier enough money for one item,
        // and will therefore receive change
        chris.collectDollars(30);
        chris.printReceipt();
        chris.refundExtra();
        System.out.println();
        
        // Second shopper gives cashier only a ten-dollar bill
        chris.collectDollars(10);
        chris.printReceipt();
        chris.collectDollars(-10);
        chris.collectDollars(20);
        chris.printReceipt();
        chris.refundExtra();
        System.out.println();
        
        // Cashiet prints total receipts for her shift so far
        System.out.println("Total collected today by current "
                        + "cashier: $" + chris.getSum());
                    }
                }
                
             
                
        
    
    
            


