Programming Assignment #2
It is recommended that a pair of students do this project together, although working alone is allowed. Let me know in advance who you are working with for each project. If working as a pair, make sure that both of you understand all aspects of the assignment. It is a tricky exercise to split up the work and both be involved in the entire process.
Project # 2 Implementation of UnboundedInt class
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 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 a minimum:
This constructor will take a string of digits(no commas) and turn it into an UnboundedInt object (MUST BE STRING INPUT)
UnboundedInt add (UnboundedInt )
A method that adds the current UnboundedInt with a pass in one. The return is a new UnboundedInt.
UnboundedInt multiply (UnboundedInt ) - do this one last!
A method that multiplies the current UnboundedInt with a pass 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
String toStringNoCommas( ) –optional (may be helpful)
same as toString but no commas in string.
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 the 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 use this at all as you are building this yourself.
Lastly, you must create a Test (driver) class that allows the user to create Large Numbers and test your arithmetic using your class.
The Test program will ask the user to input, without commas, two large numbers. You will read them in as strings and then use your constructor to make then into stored UnboundedInt objects. Then the program will have a menu output to the screen with the following choices:
These choices will allow the user and you to test your class well. After each choice is finished the menu should pop up again to reshow the choices.
Tips for good grades:
Each of these classes must be done in a separate file. Name them UnboundedInt.java, and LargeNumberTest.java. (IntNode.java should be there as well – but not altered). If you do not name these files correctly, you will lose points. Use Javadoc to create the documentation for your ADT class (UnboundedInt.html). Javacdoc comments are not required for your test(driver) program.
DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma
Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t
Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th
1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of
1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of