1. Engineering
  2. Computer Science
  3. java help create an immutable data type numbers for integer...

Question: java help create an immutable data type numbers for integer...

Question details

JAVA HELP

Create an immutable data type, Numbers, for integer values that supports addition and division.

Your ADT will have the following API:

1) Numbers(int number1, int number2) taking two inputs ONLY INT

2) Numbers plus(Numbers b) sums of this Numbers and b

3) Numbers divideBy(Numbers b) quotient of this Numbers and b

4) Boolean equals(Object that) is this Numbers equal to that?

5) String toString() string representation

Example plus method:

step 1. add the values of the instance variables of the object the plus method is called on and store the result

step 2. add the values of the instance variables of the object passed to the plus method and store the result

step 3: create a new Numbers object and pass the result from step 1 as the first argument and pass the result from step 2 as the second argument

return the object from step 3

step 4. In your client class, print the returned object (Ensure your Number class overrides the toString method)

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