Question: Given the interface BigNumberInterface.java and the application BigNumberApplication.java, implement the class BigNumberImplementation.java that can be used for addition,subtraction of real values that can have up

Given the interface "BigNumberInterface.java" and the application "BigNumberApplication.java",

implement the class "BigNumberImplementation.java" that can be used for addition,subtraction of real values that can have up to 100 digits.

- BigNumberInterface.java

package reviewAbstractionInterfaceImplementationPackage.interfaces;

public interface BigNumberInterface { BigNumberInterface add (BigNumberInterface o); BigNumberInterface sub (BigNumberInterface o); }

- BigNumberApplication.java

package reviewAbstractionInterfaceImplementationPackage.applications;

import reviewAbstractionInterfaceImplementationPackage.implementations.BigNumberImplementation; import reviewAbstractionInterfaceImplementationPackage.interfaces.BigNumberInterface;

public class BigNumberApplication {

public static void main(String[] args) { BigNumberInterface n1 = new BigNumberImplementation(0.123456789012345678); BigNumberInterface n2 = new BigNumberImplementation(0.123456789012345678); BigNumberInterface sum, diff; sum = n1.add(n2); diff = n1.sub(n2); System.out.println("Sum = " + sum); System.out.println("Diff = " + diff); }

}

- BigNumberImplementation.java

package reviewAbstractionInterfaceImplementationPackage.implementations;

import reviewAbstractionInterfaceImplementationPackage.interfaces.BigNumberInterface;

public class BigNumberImplementation implements BigNumberInterface { private double value;

public BigNumberImplementation(double value) { // TODO Auto-generated constructor stub this.value = value; }

@Override public BigNumberInterface add(BigNumberInterface o) { BigNumberImplementation sum = new BigNumberImplementation(0); sum.value = this.value + ((BigNumberImplementation) o).value; return sum; }

@Override public BigNumberInterface sub(BigNumberInterface o) { BigNumberImplementation sum = new BigNumberImplementation(0); sum.value = this.value - ((BigNumberImplementation) o).value; return sum; }

@Override public String toString() { return ""+ value; }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!