logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Denis GibbsStatistics
(5/5)

909 Answers

Hire Me
expert
rahul kumarOthers
(/5)

791 Answers

Hire Me
expert
Mitch BennLaw
(5/5)

780 Answers

Hire Me
expert
Ata WhbaLaw
(5/5)

780 Answers

Hire Me
Data structures & Algorithms

Implementation of UnboundedInt class will contain at least three instance variables the number of Nodes, Link to front of list, Link to back of the list

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

 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 number of Nodes
  • Link to front of list
  • Link to back of the list
  • Optional – a cursor that points to an 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 a minimum:

            Constructor(String)

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:

 

  1. Display both numbers (with commas)
  2. Input two new numbers (without commas)
  3. Check if numbers are equal
  4. Report the sum of the two numbers
  5. Report the multiplication of the two numbers
  6. Create and output the clone of the first number
  7. Quit

 

 

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:

 

  • Use of your programs should be user friendly- I should not have to wonder if the computer is waiting for me to input a value without having been given direction to.
  • Make sure you use comments where needed and use variable names that make sense, some of your grade will depend on program style as well as the use of your program.
  • Make sure your name and partners name are included at the top of all files submitted.
  • You will lose points for things like not indenting, or naming variables in non-descriptive ways. Do no leave in debugging code, or commented out code.
  • I use jGrasp and the java version that is in the lab computers. So make sure that your programs work with this.
  • Test your own projects thoroughly before you hand them in.
  • Late projects will not be accepted so plan ahead.
  • Any exceptions that are possible to be thrown from the class must be caught in the driver class. There should not be any occasion where the class crashes and ends the program.
  • Javadoc comments must be throughout your ADT class (UnboundedInt) but is not needed in the driver class. (But regular comments are still needed there!)

 

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.

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme