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!
- The hw instructions from hw1 all apply here.
In particular:
- This is not a lab and this is not
collaborative!
- You must work alone on this assignment
(except for help from CA's or the course instructor, who you are always
welcome to consult).
- Submit all your source (.java) file(s) all in a single zipped folder,
hw3-<andrewId>.zip, sent by email as an attachment to your CA. For
example, I would submit hw3-koz.zip (you should replace "koz" with your
andrewId).
- Do not submit .java~ files (with the tilde
(~) at the end). These are DrJava backup files. They are not
useful.
- Do not submit .class files. These are
compiled bytecode files. They also are not useful.
- Do not submit project files or any other
files. Just .java files
and your one free-response file.
Programming guidelines:
- Style counts!!! Use well-named
variables, proper indenting, reasonable commenting, etc.
- Note: You may use conditionals ("if" statements
or ternary operators (?:)) starting this week! However, you may not use
Java concepts we have not yet covered, including loops (do/while/for),
arrays, or methods from any classes in java.util.* (besides Scanner or
others we explicitly use) to solve these problems (which isn't a problem for
most of you, seeing as we have not yet covered these!). While they may be
helpful, every problem here is solvable without them, and they are not
permitted for now.
- Simple Calculator
-
Bonus/Optional: Simple Calculator Extensions
- Simple Calculator
For this question, you are to write this simple calculator:
Hw3SimpleCalcDemo.jar
(also available in Hw3SimpleCalcDemo.zip)
To complete this question:
- Download and run the demo program (Hw3SimpleCalcDemo.jar), which shows
how this program should work once it is completed.
- 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.
- Read the comments at the head of the Hw3SimpleCalc.java file. Read
them very carefully!
- 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!
- When completed, submit your completed Hw3SimpleCalc.java file.
-
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:
- 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.
- 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!