Computer Science 121
Example using an array

import java.util.*;
import simpleIO.KeyboardReader;

// Main class that declares a class that describes a store clerk and calls the methods.
public class Store8
{
    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 numberPrices = 0;
    private double [] prices;

    Clerk ()
    {
        numberPrices = 0;
        prices = new double [10];
    } // constructor

    // Method that reads the price of a product from the keyboard and stores them in an array.
    // It uses a StringTokenizer to read all prices on the same line.
    public void readPrices ()
    {
        double price;
        String priceList;
        try
        {
            System.out.print ("Enter prices, separated by spaces. ");
            priceList = KeyboardReader.readString ();
            StringTokenizer priceString = new StringTokenizer (priceList);
            while (priceString.hasMoreTokens ())
            {
                price = Double.valueOf (priceString.nextToken ()).doubleValue ();
                prices [numberPrices] = price;
                numberPrices ++;
            }
        } // try block
        catch (NumberFormatException ex) { System.out.println ("Number format error.");}
    } // method getPrice

    // Method that calculates the tax.
    private double calculateTax (double sum)
    {
        final double taxRate = 0.0825;
        double tax = sum * taxRate;
        return tax;
    } // method calculateTax

    private double calculateTotal ()
    {
        double total = 0;
        for (int count = 0; count < numberPrices; 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 " + numberPrices);
        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