You have written thest two classes in assignment 7:
Fraction -- An object of this class represents a
fraction. The class contains methods for operating on the fraction.FractionTest -- A JUnit test class for the functions
defined in Fraction.Your assignment this time is to write a GUI (Graphical User Interface), using Swing, to create and display a working calculator for fractions.
Name your project FractionCalculator, your package fractionCalculator,
and define your class as class FractionCalculator extends JFrame.
In assignment 7 I did not specify the name of a package, so you probably
used a name like fraction, or if you put the tests in a
separate package, it might be something like fractionTest or
testFractions. Whatever those packages are named, copy
them from the earlier assignment and paste them into
this assignment. If they were in the default package, create a package or
packages to put them in; don't put them in the fractionCalculator
package. Do not simply link to those classes; they must
be included in your new FractionCalculator project.
Write a GUI that looks like a "real" calculator, the kind you can buy in
any drugstore. Except, your calculator will deal only with fractions. It
should use a JTextField to display the fractions, and a
number of JButtons to do the arithmetic. To prevent the user
from typing directly into the display, send the text field the message setEnabled(false).
JButtons
with digits and the / character on them. +,
-, ×, and ÷.
× and ÷ are not on your
computer's keyboard; use new JButton(((char)215) + "")
and new JButton(((char)247) + ""), respectively, to
create buttons with the correct characters on them. (char)8592 ), clear the
current entry, and clear all (reset everything).= button. "Real" calculators do all sorts of weird things. For example, entering
2 + = will probably result in 4. To avoid dealing
with all kinds of special cases, your fraction calculator should follow
some different rules.
numerator/denominator, or
it should contain the word Error. If it contains the word
Error, the user should not be able to do anything more
until the "clear" or "clear all" buttons are clicked.Fraction) in
"memory". /, or a
fraction containing a single /. If the user hits a wrong
digit, or a slash in the wrong place, it can be backspaced over. +, -, ×,
and ÷, take the number that was saved, apply the operation
to that and the number in the display, and put the result in the
display. The result should also be saved away in memory.
0.
If the user enters, 1 / 2
+1/2 is added to 0,
and 1/2 is displayed. If the user then enters 1
/ 1 0 -1/10 is subtracted from 1/2, and 2/5
is displayed.+, -, etc.) in a row. If
you follow the above rules, the result will be sensible. Error should be displayed when the user
attempts to divide by zero, or tries to use a syntactically incorrect
"fraction". Neither of these should affect the number in memory, which
must be a legal Fraction at all times. If you have a question about how the calculator should work, and you don't think it is answered by the above rules, post on Piazza.
Good comments and good style are required, as always. Also, remember you can use SwingExamples.jar for examples of how to do various GUI things.
Turn in your one zip file to Canvas by 6am Wednesday, November 4.
Notes on submitting your work: