CS 50 Homework 3 (Section 1 Prof. Marshall)
Due by class time Tuesday, February 12
- Programming Exercise P2.9 (page 96). Name your program
Change. The output of your program should look something like this:
DOS> java Change
Amount due: 4.31
Amount received: 10.00
Here is your change:
5 dollars
2 quarters
1 dimes
1 nickels
4 pennies
Files to submit: Change.java
- Programming Exercise P3.2 and P3.3 (page 136). Name your
test program TestEmployee. Make sure that your program also tests
out the raiseSalary method added in P3.3. Files to submit:
Employee.java, TestEmployee.java
- Programming Exercise P3.4 (page 136). Name your test program
TestCar. Files to submit: Car.java, TestCar.java
- Programming Exercise P3.7 (page 137). Name your test program
TestStudent. Files to submit: Student.java, TestStudent.java
- Programming Exercise P3.8 (page 137). Name your test program
TestProduct. Files to submit: Product.java, TestProduct.java
- Finish the design of the Ratio class discussed in lecture. This
class should support the following mathematical operations on rational
numbers: addition, subtraction, multiplication, division, and inversion
(reciprocation). Also, you should be able to construct ratios from either a
numerator-denominator pair, a single integer, or with no parameter at all (in
which case the default value is the ratio 1/1). Use Ratio.java and TestRatio.java as your starting point for this
problem. The output of TestRatio should look something like this:
DOS> java TestRatio
r1 = 1.3333333333333
r2 = 1.5
r3 = 0.1666666666666
1/r3 = 6.0
Files to submit: Ratio.java, TestRatio.java
Turning in Your Homework
To turn in your homework, put the specified files into a single folder
named Your Name HW 3 and drop this folder into the drop box.
If you are an off-campus student, you may copy your folder to a CLEAN floppy
disk (one containing no other files or folders), and hand this in at the
beginning of class, instead of using the drop box.