Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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. public interface Listk extends IterablexE> Pee Should an object to the beginning. eparam obj the object to be added. public void addFirst(E obj) Should adds an object to the end param obj the object to be added. public void addLast(E ob3) Should remove the first object in the list and returns that object. Should returns null if the list is empty *ereturn the object removed. public E removeFirst); Should remove the last object in the list and returns that object. Should return null if the list is empty ereturn the object removed public E removelastO Should return the first object in the list, but does not remove that object. Should return null if the list is empty ereturn the object at the beginning of the list.- public E peekFirstO Should return the last object in the list, but does not remove that object Should return null if the list is empty ereturn the object at the end of the list. public E peekLastO Should return the list to an empty state This should be a constant time operation. public void makeEmpty) Should test if the list is empty ereturn true if the list is empty, otherwise false. public boolean isEmpty); Should test if the list is full ereturn true if the list is full, othervise false public boolean isFullO Fas Should return the number of objects currently in the 1ist. ereturn the number of objects currently in the list. public int size) Should test whether the list contains an object. This will use the compareTo method to determine whether two objects are the same. param obj The object to look for in the list ereturn true if the object is found in the list, false if it is not found. public booLean contains(E obj); Should Returns an Iterator of the values in the list, presented in the same order as the list. * @see java.lang. Iterable#iterator() public IteratorcEs iteratorO HugeNumber.Java Methods getFirstNumber() getLastNumber) addFirstNumber() addLastNumber0 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 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. public interface Listk extends IterablexE> Pee Should an object to the beginning. eparam obj the object to be added. public void addFirst(E obj) Should adds an object to the end param obj the object to be added. public void addLast(E ob3) Should remove the first object in the list and returns that object. Should returns null if the list is empty *ereturn the object removed. public E removeFirst); Should remove the last object in the list and returns that object. Should return null if the list is empty ereturn the object removed public E removelastO Should return the first object in the list, but does not remove that object. Should return null if the list is empty ereturn the object at the beginning of the list.- public E peekFirstO Should return the last object in the list, but does not remove that object Should return null if the list is empty ereturn the object at the end of the list. public E peekLastO Should return the list to an empty state This should be a constant time operation. public void makeEmpty) Should test if the list is empty ereturn true if the list is empty, otherwise false. public boolean isEmpty); Should test if the list is full ereturn true if the list is full, othervise false public boolean isFullO Fas Should return the number of objects currently in the 1ist. ereturn the number of objects currently in the list. public int size) Should test whether the list contains an object. This will use the compareTo method to determine whether two objects are the same. param obj The object to look for in the list ereturn true if the object is found in the list, false if it is not found. public booLean contains(E obj); Should Returns an Iterator of the values in the list, presented in the same order as the list. * @see java.lang. Iterable#iterator() public IteratorcEs iteratorO HugeNumber.Java Methods getFirstNumber() getLastNumber) addFirstNumber() addLastNumber0 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
Step 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