CIT 591 Assignment 8: Balanced Ternary Calculator
Fall 2008, David Matuszek

# Purposes of this assignment

• Get you started with Swing.

# General idea of the assignment

Create a calculator (integer only) for BalancedTernary numbers. Make it look and act as much like a "real" calculator as possible.

# Details

An inexpensive calculator has a single-line display. Use a `TextField` for this.

A regular calculator has buttons for ten decimal digits. Yours will not-- it will have buttons for three "trits" (ternary digits): `0`, `1`, and `N`. You can enter numbers with these keys, or you can type directly into the TextField.

A calculator has buttons for `C` (clear), `AC` (All Clear) `+`, `-`, `*`,` /`, and `=` (or, if you want to get fancy, figure out how to label your buttons with `C`, `AC`, `+`, `-`, `×`, `÷`, and `=`). Your calculator should have these same buttons, and they should behave the same way. Also have a` +/- `key, to negate the number in the display (for example, from `1NN011N` to `N110NN1`, or vice versa).

The one concession we will make to decimal is this: Your calculator should have a `dec` button to change the number in the display to decimal. The decimal value will disappear the next time you hit a key.

You and your partner should each have a `BalancedTernary` class from the previous assignment. Pick whichever one looks best to you--they should work exactly the same--and use it.

You should not have to make any changes to the `BalancedTernary` class. We will not check to see whether you changed anything, but if there were any necessary changes, they mean something was wrong in the BalancedTernary class; you should try to learn from your mistakes. On the other hand, it's fine to make improvements to that class--cleaning up and simpliying code, writing better comments, etc.

# Even more details

When you are entering a number, pressing a trit key (`0`, `1`, or `N`) appends that trit to the number in the display. When you press an operation key (including `dec`), the number is considered to be "complete"--pressing a digit starts entry of a new number.

Your calculator's text area should allow entry of the largest legal balanced ternary number--the one corresponding to `Integer.MAX_VALUE`.

If you try to divide by zero, the calculator should display `Error`. It's up to you whether you want to check for overflow (a number too large or too negative to be represented by an `int`).

I've said that the user should be able to enter numbers by typing directly into the TextField. You should disallow illegal characters (`2`, `A`, `\$`, etc.) in this field. If you want to be extra nice to the user, you could allow commas and lowercase `n` (but display it as `N`).

# Due date:

Before midnight, Thursday October 30. Submit to Blackboard one copy of your project directory, properly zipped. Include the BalancedTernary files. Both your names should be in Javadoc comments in the classes. In addition, whichever of you turns the program in, should put your partner's name in the comments field in Blackboard.