Lab 1
Due Friday, 1/27/2012 - 5:00pm
- Sign up for the class mailing list at: https://groups.google.com/a/cs.usfca.edu/group/cs112
- (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.
- 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.
- You will now create a new class that will use the Calculator class. Create a class called CalculatorDriver.
- In the CalculatorDriver class, create a main method that will do the following:
- Prompt the user for two doubles and save each into a local variable.
- Declare and instantiate a new Calculator object.
- Display the result of calling the methods add, subtract, multiply, and divide on the Calculator object.
- 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.
- Create a new class Bill.
- Define the following data members for the class:
- a double TAX_RATE that will have the value .085
- a double base
- 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.
- 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.
- Implement a method getTotal that will take no input and will return the bill total. This will be the base plus the tax.
- Create a new class BillDriver.
- 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