Project 7: Another calculator

Note about projects.

As we talked about in class, you are given a choice between this project and project 8, which will be assigned Apr 20. Project 7 is worth more points than project 8 (approximately 24 points vs 10 points; project 8 will take much less time than project 7). Your project score for the semester will be calculated as points obtained divided by points attempted.

If you do both projects, I will count project 8 as extra credit--your score for project 8 will be added to your points obtained, but the points available for project 8 will not be added to your points attempted.

Project 7 is due the Apr 25, which is Wednesday of the last class-week of the semester. If you have not used any of your late days, that makes the effective due date the last day of classes. Project 8 will be due the last day of classes and no late days may be applied.


The goal of this project is to put the state pattern to use.

1. Introduction

You will be writing one last calculator program for this class. This time we'll be back to a normal calculator. But this time you will be encorporating what we learned about the state pattern in your design of the calculator.

2. Setup

In this project you will use the same GUI as last time.

cp ~tvandrun/Public/cs245/proj2/* .

3. Calculator details

Now you'll be operating under the following rules:

4. Other requirements and helpful information

Here are the requirements from project 2:

Make this program work just like a hand-held four-function calculator. You can find a decent example for reference here. Don't try to implement anything fancy; don't use Ubuntu's built-in calculator as a reference.

ConcreteCalculatorFace has a constructor that takes no parameters (as used in the example above). A window automatically appears. I've worked on the window so that it appears nicely on the machines in the lab. If you work on this project on your own computer, the window's size might not be right (it isn't, for example, on my Macintosh). You can either adjust it by mouse whenever you run the program, or you can play around with the setSize() and setLocation() methods of CalculatorFace. If you do, please remove these adjustments before turning in your code, since your code will be graded in the lab. If you do all your work in the lab, you will not need to use these methods.

In this project, you want your program to work like a real-life hand-held calculator. This is actually pretty hard to do. Even the best students rarely get full marks on the first try of this project. (Calculators will be a recurring theme in the projects of this course.)

Specifically, here are some expectations for your calculator:

Important: The "screen" on the calculator is only 15 characters wide. Java displays double numbers using more than 15 characters. Make sure that when you display results that you do not run off the end of the screen. You need to think about how to format your results. There are several ways to do this. One way is to use the DecimalFormat class described starting on pages 72-76 in Absolute Java. You also can devise your own formating strategy using String manipulation.

5. To turn in

Turn in your code by copying your directory (eg, proj7) to a turn-in directory I've made for you.

cp -r proj6 /cslab.all/ubuntu/cs245/turnin/(your user id)

DUE:Wednesday, Apr 25, 5:00 pm.


Thomas VanDrunen
Last modified: Fri Apr 13 14:51:47 CDT 2012