Computer Science 121
Assignment 4
Due: March 1, 2001

For this assignment you are to write a program that calculates the total cost of a computer. The total cost consists of the computer's price plus the tax plus the shipping charges. The price, tax, shipping charges and total are all doubles.

First read in the name, price and shipping charge for your computer. The following example shows how to read a double from the keyboard and assign it to a variable called price:

BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));
try
{
    price = Double.valueOf (stdin.readLine ()).doubleValue ();
} catch (IOException e) { System.out.println ("Format error.");}

You will have to read the shipping charge as well.

Calculate the total cost of the computer in a separate method. It should be the price plus the sales tax plus the shipping charges. Use the value of $0.0825 for the sales tax. Calculate the sales tax separately from the total so that you will be able to print it out.

Lastly, display the data on the screen. This should be in the form of a bill that shows the name, price, tax, shipping charge and total. Make sure that each number is labeled. In order to format your output nicely, use the following method. You may copy it directly into your program.

// Formats a double for string output with two decimal places.
public String decimals (double num)
{
    DecimalFormat decFor = new DecimalFormat ();
    decFor.setMaximumFractionDigits (2);
    decFor.setMinimumFractionDigits (2);
    return decFor.format (num);
} // method decimals

See the example called Store Example on the website to see how to use this method.

Hand in a printout of the program together with a disk containing the .java and .class files.