Thursday, September 30, 2010

Lab 11 - Section 6 - Double Class

Write a class called Double, which has one instance variable d of type double and has the following methods:

(1) A default constructor: Double() which sets d to 0
(2) Another constructor: Double(double initialValue) which sets d to initialValue
(3) add(double d1): adds d1 to d and returns the result
(4) subtract(double d1): subtracts d1 from d and returns the result
(5) multiply(double d1): multiply d1 with d and returns the result
(6) divide(double d1): divide d by d1 and returns the result. The division should be done when d1 != 0 else print error message

You can add some more methods, which can be applied to double. For example, you can find the absolute value of the double d.

When you are done, submit your program in the (dropbox) and also get it checked.

No comments: