CIT 591 Assignment 7: Calculator
Fall 2004, David Matuszek

Purposes of this assignment:

General idea of the assignment:

Write a calculator for either fractions or complex numbers (your choice). You probably want to use the number class you developed for the previous assignment, but that's totally up to you.

Details:

Your program should be an application, not an applet. It should use a Swing GUI.

Name your main class either FractionCalculator or ComplexCalculator, as appropriate.

Your program GUI should resemble that of a conventional calculator. It should have buttons for the ten digits 0..9, and a JTextField used to display the current value. It should not have a text field where you enter numbers (or anything else). You should not be able to type into the display JTextField.

As you enter a number, it should appear in the number display (the JTextField). That is, you can't wait until the last character is entered before you display the number; you have to be able to see what you are doing.

You should be able to access all the public methods that I defined in your Fraction or Complex class. For example, the FractionCalculator should have a key for inverse(), while the ComplexCalculator should have a key for conjugate(). You should abbreviate these names to something that fits neatly on a button.

You should not modify the Fraction or Complex class in any way (other than fixing bugs).

You have a small but interesting design problem to work out. For fractions, you want to be able to enter fractions with the "/" key, but you also want to be able to use this key to divide one fraction by another. Similarly, you want to be able to enter complex numbers with "+" or "-" in them, but you also want to be able to add and subtract complex numbers. In a typical calculator, hitting a key that isn't a digit or a decimal point ends the number. Here's what I suggest:

You will find a few extra display issues that you will need to work out.

Partners and grading:

You will be graded only on your GUI program, not on the Complex or Fraction class that it uses--so long as you get the right answers, that is. We won't deliberately look for computational errors, but if we stumble across some, you'll lose points; it doesn't matter which class is at fault. So be sure to eliminate any remaining bugs in your number class.

Your GUI should be intuitive--that is, we should easily figure out how to use it. This is admittedly a subjective judgment, but it will affect your grade nevertheless. One thing I expect is that you should be able to enter numbers as you would write them (for example, 5 / 1 2 for 5/12, 2 + 3 i for 2+3i). I strongly recommend that you have someone else try out your program while you watch silently; do this in time to fix any problems.

Although you each hand in your own program, I recommend that you work with a partner, provided that one of you does the FractionCalculator and the other does the ComplexCalculator. (It's probably a good idea to work with the same partner as last time, but that's up to you.) You can share as much code as makes sense; but the parts that are unique to your calculator, you should do yourself.

Due date:

Monday, November 15, before midnight. You have a few extra days so that the program isn't due right after the midterm exam; however, you will get a new assignment next Friday (November 12), so there will be some overlap in assignments.