Question: Project 1 : Big Numbers We know that Java can store very large numbers accurately using the long data type ( up to 9 ,

Project 1: Big Numbers
We know that Java can store very large numbers accurately using the long data type (up to 9,223,372,036,854,775,807) and using the double data type (up to 1.7e307) but with only 14-15 digits of accuracy. To get more accuracy, say up to 50 or 100 digits without dropping any, we might consider creating a linked list of digits.
Remember that our linked lists can hold only objects of a class (not primitives), so to hold digits you'll have to use objects of the Integer class.
Using the final LinkedList Download LinkedList class from the lecture as a starting point, rename it BigNumber. It will hold a linked list of Integer objects representing the numbers from 0 to 9, and -1 for a decimal point. (Even though we'll use it to hold only Integer objects, leave it generic for now: BigNumber<>.)
Enhance it to include the following methods in your class:
an addRight method has a single int as a parameter and adds that number to the back of the list representing a new least significant digit
an addLeft method has a single int as a parameter and adds that number to the front of the list representing a new most significant digit
an addDecimal method takes no parameters and adds a -1 to the front of the list representing a decimal point.
The first two methods (addRight and addLeft) above should verify that the number passed as an argument is between 0 and 9. Otherwise print an error message and return.
The addDecimal method should ensure that the list doesn't already contain a decimal point. If it does, then print an error message and return.
Place these new methods between the block comments "Add your methods below here" and "Add your methods above here".
In addition, modify the following methods:
the toString method should create and return a String of digits contained in the list including a decimal point (if present)
In main (in a separate public class), include at least 3 test cases for big numbers, each with 10 or more digits. At least two test case should include decimal points somewhere in the middle of the number (with digits on both sides). In addition to demonstrating all of the methods above, demonstrate an iterator which returns one digit at a time.
(Note: when printing the number that represents a decimal point, please print a decimal point and not the number.)
Add two more test cases which show what happens when an invalid digit is added or when more than one decimal point is added to the big number.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!