1. Engineering
  2. Computer Science
  3. for the complex class create the add and subtract methods...

Question: for the complex class create the add and subtract methods...

Question details

For the complex class, Create the add() and Subtract() methods


The add method-->Adds the current and the given complex numbers together, and stores the sum in a new Complex object. The current and given complex numbers are not altered in the process.

   @param other the other complex number to add to this one
@return the new Complex object that holds the result of the addition

the subtract method--> Subtracts the other complex number from this one, and stores the result in a new Complex object. The current and given complex numbers are not altered in the process.
  
@param other the other complex number to subtract from this one
@return the new Complex object that holds the result of the subtraction

For the money class, just write the toString method
The toString method-->Provides a string representation of the current Money object, in the form $mm.mm. Negative values have a minus sign before the dollar sign. Zero dollar amounts are represented with one zero between the dollar sign and the decimal point. Cents that are multiples of 10 still show two decimal places. (Examples: $12.34, -$6.50, $0.99, -$0.99, $0.00)

@return the string representation

Money (leaf Complex (leaft -dollars: long -real: double -imaginary: double +Money() +Money(dollars:long, cents: byte) +getDollars(): long +getcents(): byte tadd(other: Money): Money +subtract(other: Money): Money +toString(): String +Complex() +Complex(real:double, imaginary: double) +getReal(): double +getlmaginary(): double +add(other: Complex): Complex +subtract(other: Complex): Complex +toString(): String

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution