Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I was wondering if I could get help with this project, here is the prompt: Create a HugeNumber class that uses a linked list of

I was wondering if I could get help with this project, here is the prompt: "Create a HugeNumber class that uses a linked list of single digits to represent non-negative integers of arbitrary length. The class should include a method to add a new most significant digit to the existing number so that longer and longer numbers can be created. Also add methods to reset the number and to return the value of the huge integer as a String (is this toString?) along with appropriate constructor and accessor methods. In addition to the requirements given above, implement an inner class iterator which will allow you to sequence through the digits of the HugeNumber one at a time. Decide if the HugeNumber contains no digits, then converting it to a String should return a -1 or an empty string and document your decision. Submit listings of your HugeNumber class and of your driver (tester) program. Include at least 3 test cases for numbers each with 12 or more digits. Make sure to demonstrate the methods to reset the HugeNumber, to return the number as a String, and to iterate through the digits of the HugeNumber one at a time." My Code so far:

package homework11; import java.util.NoSuchElementException; public class HugeNumber { private Node head; private int size; public HugeNumber( ) { head = null; } public void add(int newNumber) { if(newNumber < 0 || newNumber > 9) { return; } else { head = new Node(newNumber, head); } } private class List2Iterator { private Node position; private Node previous; //previous value of position public List2Iterator( ) { position = head; //Instance variable head of outer class. previous = null; } public void restart( ) { position = head; //Instance variable head of outer class. previous = null; } public int next( ) { if (!hasNext( )) { throw new NoSuchElementException( ); } int toReturn = position.getNumber(); previous = position; position = position.link; return toReturn; } public boolean hasNext( ) { return (position != null); } } //End of list2Iterator private class Node { private int number; private Node link; public Node( ) { link = null; number = 0; } public Node(int newNumber, Node linkValue) { setNumber(newNumber); link = linkValue; } public void setNumber(int newNumber) { number = newNumber; } public void setLink(Node newLink) { link = newLink; } public int getNumber( ) { return number; } public Node getLink( ) { return link; } } //End of Node class public List2Iterator iterator( ) { return new List2Iterator( ); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions

Question

List and describe the four types of e-commerce presence.

Answered: 1 week ago