COMP 110-003 Fall 2008

Program 2: GUI Calculator

75 points

Assigned: Wednesday, September 10
Due: Wednesday, September 24 Friday, September 26 at 2:00pm

Description

Write a GUI-based program that mimics a calculator. The program should take as input two floating-point numbers and the operation to be performed. It should then output the numbers, the operator, and the result.

The user input should be in the format operand1 operator operand2, where the operands and the operator are separated by single spaces. For example, to add 2 and 3, the user should enter 2 + 3 in the text field of the dialog box.

You should support the following operations: addition (+), subtraction (-), multiplication (*), division (/), and mod (%).

Special cases to handle:

Here's an example run:

Here are a few tips for this program.

Note: You may ONLY use the String methods listed on pp. 80-82 (4th edition) or p. 78 (5th edition) for this assignment. In other words, you may not use other available Java libraries or methods for parsing strings.

Extra Credit:

How to turn in the assignment Requirements

When I run/examine your program, it must satisfy the following requirements. The maximum point value for each is shown in brackets.

  1. [3] Your class, Java source file, and Jar file must be appropriately named (as specified above).
  2. [2] Pledge header
  3. [5] Your printed copy of the code (Calculator.java) must be handed in.
  4. [15] You must use the JOptionPane class to create dialog boxes for user input and output (see Lab 2). Your user input dialog box should contain instructions for using the program, including a list of the supported operations.
  5. [15] You must correctly parse the user input String.
  6. [15] You must display the correct result of the calculation to the user.
  7. [10] You must convert floating-point numbers to integers to perform modular arithmetic.
  8. [5] You must use meaningful variable names, which conform to the style guidelines and Java naming conventions discussed in class.
  9. [5] You must comment your code, including block-like multi-line comments and single-line comments where appropriate. In addition, your code must be neatly and clearly formatted using appropriate "white space."
  10. [10] Extra Credit.
Notes: