Question
Make a linked list to store a large number. The BigNumber data structure (Wrapper class) will hold, do arithmetic on large numbers that Java can't
Make a linked list to store a large number. The BigNumber data structure (Wrapper class) will hold, do arithmetic on large numbers that Java can't usually do.
LinkedList.Java
ONLY use these two import java.util.Iterator; import java.util.NoSuchElementException;
Your LinkedList.java class must use these methods from the ListK.java interface. Please do not alter the ListK.java interface. The linked list must be generic and able to hold arbitrary data type.
--------------------------
HugeNumber.Java
Methods:
getFirstNumber() getLastNumber() addFirstNumber() addLastNumber() public void setNeg(boolean b) - set if positive or negative public boolean getNeg() - get whether it is a negative public int length() - length of number public void stringToHugeNumber(String s) - accept string of arbitray length and store it in linked list public String toString() - return string representation of the number.
If you think it will be more beneficial, add peekFirstNumber() and peekLastNumber().
As an example using addFirst from the linked list, to add 52373 you would do this starting with addFirst(3), and then addFirst(7), addFirst(3), addFirst(2), and finally addFirst(5).
--------------------------
Calc.Java
This class will do operations on 2 big numbers. First, convert the strings to numbers, and then the operation will be done.
Only one public method in this class: public String calculate(String n1, String operation, String n2);
Both numbers entered should be converted to HugeNumber objects from the stringToHugeNumbermethod, and then the Calc.java class should use addition, subtraction, multiplying and dividing on the 2 big numbers. So if you use the "-" operator, it will subtract number 1 - number 2 and then return the result as a string. For the actual calculating, you need to use one other huge number class to hold the result and then just return the toString() function.
public interface ListkStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started