// CS 121 Example
// Reading prices from the keyboard into an array.

import simpleIO.KeyboardReader;

// Main class that declares a class that describes a store clerk and calls the methods.
public class Store
{
     public static void main (String [] args)
     {
          Clerk storeClerk = new Clerk ();
          storeClerk.readPrices ();
          storeClerk.displayTotal ();
     } // method main
} // class Store

// Class that defines the work of a store clerk.
class Clerk
{
     private int listSize;
     private double [] prices;
 
     Clerk ()
     {
          listSize = 0;
          prices = new double [10];
     } // constructor

     // Method that reads the price of a product from the keyboard.
     public void readPrices ()
     {
          double price;
          System.out.println ("Enter prices ending with a zero price.");
          System.out.print ("Enter the first price: ");
          price = KeyboardReader.readDouble ();
          while (price > 0)
          {
               prices [listSize] = price;
               listSize ++;
               System.out.print ("Enter the next price: ");
               price = KeyboardReader.readDouble ();
          }
     } // method getPrice

     // Method that calculates the tax.
     private double calculateTax (double total)
     {
          final double taxRate = 0.0825;
          double tax = total * taxRate;
          return tax;
     } // method calculateTax
 
     private double calculateTotal ()
     {
          double total = 0;
          for (int count = 0; count < listSize; count ++)
          {
               total = total + prices [count];
           }
          return total;
     } // method calculateTotal

     // Method that calculates and then displays the total bill.
     public void displayTotal ()
     {
          double total = calculateTotal ();
          double tax = calculateTax (total);
          double totalBill = total + tax;
          System.out.println ("The number of items bought is " + listSize);
          System.out.println ("The total is $" + KeyboardReader.decimals (total));
          System.out.println ("The tax is $" + KeyboardReader.decimals (tax));
          System.out.println ("The total bill is $" + KeyboardReader.decimals (totalBill));
     } // method displayTotal
} // class Clerk