1401 Introduction to Computer Science
Objective. The purpose of this lab is to practice
Graphical User Interfaces (GUI).
Fall 2013, Lab 11
Assignment. By using a design in section 16.7 of our textbook (pp. 615-616) as a sample, create a fraction calculator.
Your calculator should enable the user to type in:
After the user presses the button marked "Compute", then, depending on the operation,
your calculator should display, correspondingly, the sum, the difference, etc. of the two
input fractions. Display the answer both as a fraction and as a decimal.
- numerator and denominator of the first fraction,
- numerator and denominator of the second fraction, and
- an operation sign (+, −, *, or /).
The calculator should have 7 fields:
Once the four numbers are read, your program should:
- two fields for the numerator and the denominator of the first fraction,
- two fields for the numerator and the denominator of the second fraction,
- one field for the operation symbol,
- one field for the resulting fraction, presented in the usual fraction form p/q (e.g., 1/2);
- one field for the resulting fraction presented as a decimal number (e.g., 0.5).
- form two objects of type Fraction,
- use a method from the class Fraction to perform the
corresponding operation, and then
- use GUI to display the result.
Comment In case you have not done so already, you can download
the source code for all examples from the textbook at the textbook web site:
http://www.cs.armstrong.edu/liang/. Select the "Solution" tab, click on
"Source Code for Examples", and follow instructions to download either one large
zip file with all book examples, or navigate to a chapter and get to a specific java file.
For extra credit. Feel free to add additional graphical features to your fractions calculator. Numerous ways to add
such features are described in Chapters 12, 16, and 17. The TAs will give extra credit for each such feature.
When it is due. Lab 11 is due at the beginning of the
first lab section on the week of November 18, i.e.:
Monday November 18 for those who attend Monday-Wednesday labs, and
- on Tuesday November 19 for those who attend Tuesday-Thursday