Question
Please design LargeInt using the following instructions and code for SpecializedList. package a1; public class SpecializedList implements SpecializedListInterface { private SListNode head; private SListNode tail;
Please design LargeInt using the following instructions and code for SpecializedList.
package a1;
public class SpecializedList implements SpecializedListInterface {
private SListNode head; private SListNode tail; private int size; private SListNode forward; private SListNode backward;
public SpecializedList() { head = null; tail = null; size = 0; forward = null; backward = null; }
public void resetForward() { forward = head; }
public byte getNextItem() { byte item = forward.data; forward = forward.next; if (forward == null) { forward = head; } return item; }
public void resetBackward() { backward = tail; }
public byte getPriorItem() { byte item = backward.data; backward = backward.previous; if (backward == null) { backward = tail; } return item; } public int lengthIs() { return size; }
public void insertFront(byte item) { SListNode node = new SListNode(item); if (head == null) { head = node; tail = node; } else { node.next = head; head.previous = node; head = node; } size++; }
public void insertEnd(byte item) { SListNode node = new SListNode(item); if (tail == null) { head = node; tail = node; } else { node.previous = tail; tail.next = node; tail = node; } size++; }
private class SListNode { public byte data; public SListNode next; public SListNode previous;
public SListNode(byte data) { this.data = data; this.next = null; this.previous = null; } } }
The lists must hold elements of the primitive type byte; duplicate elements are allowed. The only list operations that we will use, are the lengthIs operation and the iterator operations. We are going to need to process elements from left-to-right and from right-to-left, so we need to support two iterators. In addition, we are going to need to insert items at the front and at the back of our lists. Please take sometime to read the starter code. You must provide an implementation of the given interface. Please name your implementation SpecializedList. You will need to design a helper class called SListNode. Please see the following image for some examples. For the LargeInt ADT, let's start by defining an interface, LargeIntInterface. Let's put the three abstract methods that we described earlier: add, subtract, and setNegative. (Also - why did I not list toString above? Just some food for thought.) So, based on the description as well as the diagrams provided, and some further details here, these are the details of LargeInt: - Implements LargeIntInterface (per above) - Constructor takes one argument of type String - Constructor can handle positive and negative values (+, -, and no sign i.e. positive) Note: we are not expecting that inputs will have commas. - Implements the three abstract methods that you declared in LargeIntInterface: add, subtract, setNegative - add and subtract have one argument for LargeInt, and returns LargeInt. So add is z=x+y where z is the return value, and y is the argument. subtract is z=xy where z is the return value, and y is the argument. - setNegative has no argument and doesn't return anything - toString should return a String representation of the LargeInt. Note: don't print out the + character for positive integers. We only need the sign for negative integers. If your integer is negative, you should have the - character in front of the numerical value. If your integer is positive or zero, do not put any sign character (+ or ) in front of the numerical value. Commas for large numbers (ex. 1,000,000) are not required. - underlying structure must be SpecializedList (i.e. declare an instance inside LargeInt). Do not extend SpecializedList. - LargeInt may use doubly linked nodes, unlike the diagram above - LargeInt nodes do not need to store more than one digit Other than these details, you can do whatever you like to accomplish the implementation (extra helper methods, extra attributes, etc.) - Implement SpecializedListinterface as described above - Design a LargeInt ADT. Start by defining an interface called LargeIntInterface. Declare the abstract operations (add, subtract, setNegative). Implement it. We are expecting that you use SpecializedList as the underlying structure of LargeInt. Create as many helper methods as needed. - LargeInt may use doubly linked nodes (unlike the diagram above) - LargeInt nodes do not need to have more than one digit - arguments for all methods must be of the type LargeInt with the exclusion of setNegative (shouldn't have argument) - LargeInt's constructor will have one argument of type String. We will assume that the input argument is always a valid integer, in the mathematical sense - thus, we are not bounded by the limitations of the primitive int type in java. This way, you could try to put something like 9999999999999999 . Also, be prepared to accept both positive and negative valuesStep 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