Lab 1

Due Friday, 1/27/2012 - 5:00pm

    1. Sign up for the class mailing list at: https://groups.google.com/a/cs.usfca.edu/group/cs112
    2. (Optional) Install Eclipse and SVN on your personal computer. Refer to the instructions here: Eclipse/SVN Install

Programming Problems:

1. Create a new Eclipse Java Project called Calculations.

      1. Download Calculator.java and save it in the src directory of the Calculations project. Once it has been saved, go back to your Eclipse window. Expand the Calculations folder, right-click the src folder and click Refresh. You should now be able to double-click Calculator.java and see the code.
      2. You will now create a new class that will use the Calculator class. Create a class called CalculatorDriver.
      3. In the CalculatorDriver class, create a main method that will do the following:
        1. Prompt the user for two doubles and save each into a local variable.
        2. Declare and instantiate a new Calculator object.
        3. Display the result of calling the methods add, subtract, multiply, and divide on the Calculator object.
        4. The output of your program will look as follows:

Enter the first double:

5.1

Enter the second double:

2

5.1 + 2.0 = 7.1

5.1 - 2.0 = 3.0999999999999996

5.1 * 2.0 = 10.2

5.1 / 2.0 = 2.55

Once you have completed problem 1, follow the submission instructions for uploading your code to SVN.

2. Create a new Eclipse Java Project call BillCalculator.

      1. Create a new class Bill.
      2. Define the following data members for the class:
        1. a double TAX_RATE that will have the value .085
        2. a double base
      3. Implement a constructor for the class that will take as input a double representing a base bill amount and save the value in the data member base.
      4. Implement a method getTax that will take no input and will return the tax on the base amount. This will be the base times the TAX_RATE.
      5. Implement a method getTotal that will take no input and will return the bill total. This will be the base plus the tax.
      6. Create a new class BillDriver.
      7. In the BillDriver class, create a main method that will prompt the user for a base amount, create a Bill object, and use the methods of the Bill class to print the Base, Tax, and Total for the given amount. The output of your program will look as follows:

Enter the base:

100

Base: 100.0

Tax: 8.5

Total: 108.5

Once you have completed problem 2, follow the submission instructions for uploading your code to SVN.

Make sure you have submitted your work in an SVN directory: https://www.cs.usfca.edu/svn/<username>/cs112/lab1