Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your task is to create the class that is discussed in chapter 4, programming project 10 on page 249 of your textbook. You must use

Your task is to create the class that is discussed in chapter 4, programming project 10 on page 249 of your textbook. You must use a linked list of integers to store the numbers. The use of the IntNode class (unaltered) that we discussed in class from chapter 4 is expected. There is a fresh copy of this class in with this assignment. The UnboundedInt class will contain at least three instance variables:

The number of Nodes

Link to front of list

Link to back of list

Optional a cursor that points to a IntNode within the list

The idea of this class is to allow numerical values(integers) that are of any size and not limited to 32 or 64 bits of storage. To do this we will use a linked list of IntNode objects. Each Node will contain an integer value from zero to 999. In addition, when concatenated together this will allow us to store values with almost unlimited size.

Although you can store the representation of your numbers in either way, it makes more sense if you do the lower value terms at the front of the list. For example, to represent the number 12,453,075 you would put a 75 in the first Node, then a 453 in the second and a 12 in the third. This order will help you when you are attempting to add or multiply two numbers of unknown length. Note: each node is assumed to store 3 digits of the full number, so values of less than 100 are still storing place holders.

Your class must have the following methods at minimum:

Constructor(String)

This constructor will take a string of digits and turn it into an UnboundedInt object (MUST BE STRING INPUT)

UnboundedInt add (UnboundedInt )

A method that adds the current UnboundedInt with a passed in one. The return is a new UnboundedInt.

UnboundedInt multiply (UnboundedInt ) - do this one last!

A method that multiplies the current UnboundedInt with a passed in one. The return is a new UnboundedInt.

void addEnd ( int ) -optional method (helpful)

A method to add a new element at the end of the sequence , used for building up each higher term in a single sequence. (i.e. adding a new IntNode to the linked list)

UnboundedInt clone( )

a method that returns a copy of the original structure

boolean equals ( Object )

a method that returns true if linked list represents the same numerical number as the input parameter. False otherwise. Overrides method in Object class.

String toString ( )

creates a string of all elements in order separated by commas, making sure leading zeros are added when needed. (i.e. 12,005,016 or 34,000 )

Throw an IllegalStateException if the sequence is empty

void start( ) optional (useful if you add a cursor variable into class)

set the cursor to the front of the list

void advance( ) optional (useful if you add a cursor variable into class)

move the cursor along the list

Throw an IllegalStateException if the cursor is null

int getNodeValue ( ) optional (useful if you add a cursor variable into class)

a method that returns the integer value of the Node that is pointed to by the cursor.

Throw an IllegalStateException if the cursor is not pointing to a Node

For each method added you need to also add the specifications in the Javadoc comments. You can have more methods than this if needed.

HINT: I would create your constructor and your toString( ) methods first because without these it would be difficult to test any parts of your class.

VERY IMPORTANT: The purpose of this class is to allow us to store numbers that are larger than the standard types. If at any time you are asking user to input integers, storing your number as an int or long, or having your constructor read in something as an int or long you are doing it wrong. There also exists a class in the java library called BigInteger which does some of what I am asking you to do. I do not want you to attempt to use this at all or you are trying to get out of creating the work yourself.

textbook text ------------->

You can represent an integer with any number of digits by storing the integer as a linked list of digits. A more efficient representation will store a larger integer in each node. Design and implement an ADT for unbounded whole numbers in which a number is implemented as a linked list of integers. Each node will hold an integer less than or equal to 999. The number represented is the concatenation of the numbers in the nodes. For example, if there are four nodes with the four integers 23, 7, 999, and 0, then this represents the number 23,007,999,000. Note that the number in a node is always considered to be three digits long. If it is not three digits long, then leading zeros are added to make it three digits long. Include methods for the usual integer operators to work with your new class.

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_2

Step: 3

blur-text-image_3

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

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

Define and describe contribution margin per unit.

Answered: 1 week ago

Question

Explain the development of human resource management (HRM)

Answered: 1 week ago

Question

2. (1 point) Given AABC, tan A b b

Answered: 1 week ago