Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Book: Data Structures: Abstraction and Design Using Java (Koffman and Wolfgang)

ID: 3623178 • Letter: B

Question

Book: Data Structures: Abstraction and Design Using Java (Koffman and Wolfgang)
Chapter 1 Review Question 10

Define an interface to specify an ADT Money that has methods for arithmetic opertaions (addition, subtraction, multiplication, and division) on real numbers having exactly two digits to the right of the decimal point, as well as methods for representing a Money object as a string and as a real number. Also include methods equals and compareTo for this ADT.

I have no clue how to do this problem!

Explanation / Answer

public interface Money extends Comparable<Money>
{
/**
* Add the given amount to this money
*/

public abstract void add(double amount);

/**
* Subtract the given amount from this money
*/

public abstract void subtract(double amount);

/**
* Multiply this money by the given value
*/

public abstract void multiply(double amount);

/**
* Divide this money by the given value
*/

public abstract void divide(double amount);

/**
* Represent this money as a string
*/

pubilc abstract String toString();

/**
* Represent this money as a real number
*/

public double getValue();

/**
* @return whether this money is equal to rhs
*/

public boolean equals(Money rhs);

// money must implement compareTo() from Comparable
}