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.
Your program should be an application, not an applet. It should use a Swing GUI.
Name your main class either
Your program GUI should resemble that of a conventional calculator. It should
have buttons for the ten digits
0..9, and a
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
As you enter a number, it should appear in the number display (the
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
Complex class. For example, the
should have a key for
inverse(), while the
should have a key for
conjugate(). You should abbreviate these
names to something that fits neatly on a button.
You should not modify the
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 "
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 "
-" 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:
=key for ending a whole number (so you can type
1 2 3 =rather than
1 2 3 / 1, for example).
/" is treated as part of the fraction, but a second "
/" indicates a divide operation (and you enter the completed fraction and start work on the next one)
=key for ending a number that consists of only a real part.
ikey for ending a number that consists of only an imaginary part.
+" or "
-" after some digits have been entered is treated as introducing the imaginary part.
ikey, or any other key that isn't a digit or period.
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
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
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
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.
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.