Skip to content

drmito/Data-Structures-Class-Repo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Assignment 1 Data Structures

The impossibly big number calculator The problem with numbers is that they are so limited. You can't easily do arithmetic on very large numbers. How large? Well, there are an estimated 300,000,000,000,000,000,000,000 stars in the sky (according to fox news). There may be as many as five million trillion trillion 5,000,000,000,000,000,000,000,000,000,000 bacteria living on Earth (according to Science-A-Go-Go)! Can you store those numbers in a Java Primitive Data Type? We may want to store some really big numbers, for example to know how many stars our telescope has looked at as it traverses the night sky. We might also want to sum the number of stars that all the telescopes in all the would have looked at. This would be too large to calculate using Java. To do arithmetic on such large numbers we need to turn to a data structure that is not limited by the size of an int or a long, so we will have to make our own data structure. Our BigNumber data structure will be able to hold, and do arithmetic, on impossibly big numbers that Java can not normally cope with. In fact, we will need to hold a number sooooo big that even an array will not suffice. For the first assignment you will make a data structure based on a Linked List. Each node of your data structure will hold a single number, but together the whole data structure will represent the entire number. For example, the number 1234 will be represented in four different nodes:

                   Node 1                         Node 2                      Node 3                          Node 4  
                   data: 1                        data: 2                     data: 3                         data: 4 
                   next: Node 2                   next: Node 3                next: Node 4                    next: null   

Similarly, the number 123456789012345678901234567890 will be represented by 30 different nodes, each holding a single digit. The Linked List that you write must be generic because you will use it (or parts of it) in Assignment 2. The Linked List MUST implement the ListI interface that I have provided in your class accounts.

In addition to the Linked List, you will also write a class called BigNumber. This class will use the Linked List to store and retrieve your Big Number. The methods that this class should encode include:

  • public ---- getNextDigit( ---- ) - retrieve the next digit from the number. For example, if the number is 1234, repeated calls to getNextDigit() will return 1, and then 2, and then 3, and then 4.
  • public ---- addDigit( ---- ) - this will store the next digit in the number.
  • public --- getFirstDigit()
  • public --- getLastDigit()
  • public --- addFirstDigit( --- )
  • public --- addLastDigit( --- ) {
  • public int length() - this method will return the length of the number.
  • public void convertStringToBigNumber(String s) - this method will accept a string of arbitrary length and add store it in the linked list
  • public String toString() - this method will return the string representation of the number (i.e. 1234 for the above example).

Note: For getting and adding digits you will have to decide the most appropriate return type and parameters! We shall discuss this in class You may also want to write a peekFirstDigit and peekLastDigit method if you think that these will help. Mostly, this will be a wrapper class that will call the appropriate methods in your Linked List class. Notice, for example, that length() can just

return the value of size() in the linked list class, like this: public int length() { return numberList.size();
}

You are also required to write a Calculator class. This class will only have one public method which has the following signature: public String calculate(String number1, String operation, String number2);
The two numbers should be converted to BigNumber objects (for example, by the convertStringToBigNumber() method in that class), and then separate (non-public) methods in the Calculator class will implement addition, subtraction, multiplication, and division of the two big numbers, depending on whatever the operator is. For example, if the operator is "+" then we will add number1 and number2 and return the result as a string. Both the BigNumber and the Calculator classes will need to have constructors! Grading policy Grades will be assigned as discussed in class and include:

  • 15% for CVS commits. You should commit your code to the repository at least once per week.
  • 15% for Javadoc. Your code should include appropriate Javadoc comments for all methods -- include those that implement interface methods whether or not the interface has comments.
  • 60% for code that compiles without error, and runs the program as described.
  • 10% for coding style. Pay attention to the Good Programming Practices of Riggin's reader. File output Your files should not print out extraneous information (for example, debugging or other information). None of the classes described here (BigNumber, Calculator, LinkedList, ListI, etc) need to print out anything. You will loose marks if your code prints out things it does not need to. Submitting Your Work The last time stamp that you submit your work to the CVS repository will be the time used for the submission. You should submit your work to CVS before the deadline to avoid a late penalty. You will also need to print out your code and submit it to Dr. Edwards. You can either submit the print out in class or in GMCS536

About

Assignments for class

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages