CIS 211 - Computer Science II
Winter, 2003 - A. Hornof
Project written by Jimmy Huang
Posted and handed out on 2/28/03

Extra Credit Project

This is an optional extra credit project that you can do to raise the lowest score that you received on Projects 1 through 4.

If you choose to do this project, it is due on Friday, March 7. It may, however, be submitted up until Wednesday, March 12, at 5 PM, with no late penalty whatsoever.

See the important updates on the Project 7 Addendum page.

Purpose

This project will give you practice the following programming techniques:

  • Develop graphical user interface using the Java Swing libraries.
  • Creating listeners for listening events from different components of the GUI.
  • Read inputs from the GUI and display output to the GUI as well.
  • Simulate arithmetic function of calculators.

Overview

In this project, you will write a simple integer calculator using Java Swing. The calculator has the four basic arithmetic functions--addition, subtraction, multiplication, and division. 

Specification

Your calculator should have the following components in the GUI:

  • A text field for displaying the result
  • A Keypad made up with buttons for each of the ten digits 0 to 9.
  • A button for each of the four simple arithmetic functions: +, -, x, /
  • A button for the = sign obtain the results.
  • A button that clears the display.
  • Use layout managers to organize you GUI. There are no specification on the look of your calculator, but it should be easy to use, simple in design, and similar to standard calculator.
  • Put a border around the buttons to separate them from the output display.

You calculator should have the following behaviors:

  • Assume that the inputs are only integers.
  • Correctly display the number entered as the user enters the numbers.
  • Correctly display the result of any of the four arithmetic functions after the °=° is pressed
  • The clear button will clear the display as well as all current arithmetic operations.
  • Round all division results to the the nearest integer.
  • Display "Error" in the calculator's output display if the user tries to divide by zero.
  • Allow the user to either click on the Swing buttons or to use corresponding keys on the keyboard. This will require your program to listen for keyboard events.

What to Turn In

Put all your well-commented code into a single "Calculator.java" file and submit it via e-turnin. Your program should compile and run by typing "javac Calculator.java" and "java Calculator" on the command line.

Grading Criteria

You will receive credit for programs that compile using the correct package declarations and that solve the problems as specified. You will not receive any credit for code that does not compile from the command line using Java 1.4.1.