Overview Schedule Announcements Resources Assignments Home

CSC 121: Computer Science I, Spring 2005

Project 2

A Calculator Simulator - GUI and Stacks
Deadline: 5:00pm, Wednesday, March 30

Calculator GUI before and after

Items to do and point distribution:

You have already been working on this project and are almost finished. The items to be completed, including what you have already done are:

  1. * (10 pts) Add new buttons *, /, (, and ).
  2. * (10 pts) Enable event handling for * and / together with the ability to multiply and divide.
  3. * (10 pts) Define Stack methods push, isEmpty and makeEmpty.
  4. (15 pts) Define Stack method stackDump.
  5. (10 pts) Use stackDump in the CalcEngine as described below in the Details section.
  6. (25 pts) Add a new operator, ^, for exponentiation, so that 3 ^ 4 = 81.
  7. (10 pts) Find and correct an error in how one of the operators, +, *, -, / works.
  8. (10 pts) Programming style, formatting (readability), and comments, especially describing methods.

* You should have already completed this.

Details:

You have been given a calculator project that will function once you complete item 3 above. You should have completed item 3 in lab 6. Following are the details for items 4 through 7.

Item 4: Write a stackDump method in the Stack class. This method will remove all items from the stack, but before doing so will display the contents of the stack from top to bottom in a terminal window.

Item 5: Modify the CalcEngine class so that it calls the stackDump method if division by zero could occur, and call it anywhere else that the keySequenceError() method is called. That is, replace the keySequenceError() call with the stackDump() method call. Be sure to test this change by entering a calculation such as 1 + (2 / 0), and verifying that the correct stack contents are displayed.

Item 6: Add a '^' button to the calculator GUI interface. There is one empty spot for it. You can place it where you wish, but all operators should be grouped together. The simplest thing to do is to put '^' in the empty spot. Enable event listening for '^' and write the statements necessary for the operation to be carried out. As an overview, if 4 ^ 5 is entered, you will need a while loop that produces a result of 4*4*4*4*4. Don't forget to handle special cases like 4 ^ 0 and 0 ^ 4. Note: Java does not have a built-in integer exponentiation operator, so you should use a while loop for ^.

Item 7: There is a 'bug' in the calculator, left there by an incompetent programmer. One of the operators doesn't produce the expected result. Your job is to find it and fix it!

Turning in your project:

Copy your project to the appropriate CSC121 folder in the Project2 folder on the I: drive. Send an email message to your instructor when you have done this, naming the programmer or pair of programmers who completed the project.

Overview Schedule Announcements Resources Assignments Home

Valid HTML 4.01!Valid CSS!DePauw University, Computer Science Department, Spring 2005
Maintained by Brian Howard (bhoward@depauw.edu). Last updated