Computer Science 15-110, Lecture 9 (Sections M-Q), Fall 2009
Homework 3
Due:  Thu 17-Sep-2009 at 11:59pm (email copy to your CA)
(no late submissions accepted).


Read these instructions first!



Programming guidelines:

  1. Simple Calculator
  2. Bonus/Optional:  Simple Calculator Extensions

  1. Simple Calculator
    For this question, you are to write this simple calculator:
         Hw3SimpleCalcDemo.jar   (also available in Hw3SimpleCalcDemo.zip)
    To complete this question:
    1. Download and run the demo program (Hw3SimpleCalcDemo.jar), which shows how this program should work once it is completed.
    2. Download Hw3SimpleCalc.java.  This file contains most of the solution already written for you, making your job much easier.  It also contains the specifics for the assignment, so you really must start from this file.
    3. Read the comments at the head of the Hw3SimpleCalc.java file.  Read them very carefully!
    4. Find each @TODO in the Hw3SimpleCalc.java file -- these explain each step in the assignment.  There are 16 steps, but most are fairly simple (though a few might be a bit more challenging).
      Hint:  the program says it passes all tests now, but that's only because the tests themselves are very incomplete!  Part of your assignment is to write reasonable tests!
    5. When completed, submit your completed Hw3SimpleCalc.java file.
       
  2. Bonus/Optional: Simple Calculator Extensions
    Here are two extensions you may add to the simple calculator for bonus.  If you plan to do these, first copy your final solution to Hw3SimpleCalc.java to a new file, Hw3BonusCalc.java, and then add these bonus features to that bonus file:
    1. Backspace
      Add the ability for the user to enter a backspace, which undoes the last letter typed.  The user should be able to backspace multiple times, back through the equals sign (if entered), back through the right-hand side, back through the operator, and finally back through the left-hand side.  If the user enters backspace with no left-hand side, an error message should be displayed.
      Hint:  JComponentWithEvents defines the BACK_SPACE constant, which you can use to test the key against in the keyPressed() method.
       
    2. Two Operators with Precedence
      Add the ability to handle expressions with two operators, such as "1+2*3=".  You should respect order of operations, so "1+2*3=" evaluates to 7, but "1*2+3=" evaluates to 5.  You should also still support just one operator, as in "1+2=".

Carpe diem!