Week 3 Exercises

  1. Implement the Money class discussed in class. This class should represent a dollar and cents amount with 0-99 cents and the cents being the same sign as the dollars. The class should at a minimum have getter methods that return the dollars and cents, a toString() method, all reasonable constructors, addition and subtraction methods, and a main() method that provides a thorough test of all the methods in the class.

    This should not be a hard problem. 90% of it was done for you in the third class.

  2. Implement the Angle class discussed in class. This class should represent a mathematical angle with a guaranteed value between 0 and 360 degrees; that is, 0 <= degrees < 360. (Note that 0 and 360 are not symmetric. 0 is valid value while 360 is not.) The class should at a minimum have getter methods that return the radians and the degrees, sine, cosine, tangent, secant, cotangent, and cosecant methods, a toString() method, all reasonable constructors, and a main() method that provides a thorough test of all the methods in the class.

  3. Implement the complex number class discussed in the lecture. At a minimum it should have a constructor, a toString() method, and methods to add, subtract, and multiply two complex numbers, and to return the real and imaginary parts.

    You may wish to attempt to implement division, absolute value, and argument methods as well. If so you will need to look ahead a little to learn about java.lang.Math. In particular, you'll need the trigonometric and square root functions.


Start | Previous | Cafe au Lait

Copyright 1997-1998 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified January 9, 1998