Java Lab #8: Clacky v1.1

In this lab you will enhance Clacky to use rational numbers and to provide a way of storing computed values temporarily. This lab gives you some practice creating your own class and using exceptions. The starting point for this lab is the Clacky v1.0 code in Lab #7.

Proceed as follows

  1. ​Using the class Rational I discussed in lecture, modify Clacky so that it uses Rationals throughout instead of BigIntegers. Because class Rational has a constructor that knows how to handle integer strings such as "42" and since it has a toString method that knows not to print denominators of "1", Clacky should continue to process integer values in a natural way.

  2. Add a class InMemoryStorage that provides an open ended collection of "registers" where values (rational numbers) can be stored. Your class should include three methods (you can define others if you want... but that's not required). Note that you might need to define a constructor method to initialize an InMemoryStorage object (or you might not). The methods required are as follows.

  3. Modify Clacky to create an instance of InMemoryStorage and then implement commands such as "store" and "recall" that use it. For example

            > 5 store

    The above stores stack level zero into register 5 (notice that it pushes 5 first and then the "store" command pops that value off the stack and uses it as the register number).

            > 5 recall

    The above pushes onto stack level zero the value previously stored in register 5.

  4. Negative register numbers are not allowed. If the user attempts to specify a negative register number your InMemoryStorage class should throw an exception. This last part is tricky. You will see a ripple effect from the exception. That's how it goes!

If you want you can also modify your program to use my ClackyStack class that I talked about in the lecture. The advantage with that is it cleans up the code quite a bit (the representation of the stack becomes hidden inside the class). However it requires additional fussing with the program. I leave it up to you to decide if you want to bother with it right now.

As a final optional step, consider exporting your program to an executable jar file as I demonstrated in the lecture. This would allow you to use Clacky outside of Eclipse and makes the program much more practical. Turn in your final program with appropriate comments. I'm mostly interested in just the file. I don't need to see your modified Be sure your name is on your submission.