Seventh Assignment: Calculator
CIT 591, David Matuszek, Fall 2001

Purposes of this assignment:

Your assignment:

You are to implement a calculator. This calculator has the following features:

I am providing a CalculatorChip class which does all the mathematical operations for you. Your job is to write the GUI for this chip. Download CalculatorChip.java and use it in your project.

Your GUI should include:

These buttons should call appropriate methods in a CalculatorChip object.

In addition, you have the following requirements:

How to get started:

Use BlueJ to create an Applet. You can ignore most of the methods that it creates; the only one of interest in the public void init() method. This is the applet method you will modify to create the GUI. (Of course, you are welcome to create additional methods.) The applet and its init() method provide both the controller (the buttons) and the view (the text field).

In the init() method, create the TextField and the Buttons you will need. Figure out how you will nest containers (Panels), and which layout manager you want to attach to each container. Add all your components (containers included) to the appropriate containers (your Applet, this, is the largest container). You might want to look at RabbitHunt for examples.

Make an instance of the CalculatorChip class. Look at the methods it provides, then attach listeners to your buttons. Each listener should call the appropriate method in the calculator chip, and send the result to the text field. Notice that the calculator chip, which represents the model, does not use your controller or your view; it is completely independent of them.

When you attach one listener to multiple buttons, you need to find out which button caused the listener to be invoked. Remember that the listener gets an ActionEvent object as a parameter, and it contains the information you need.. The ActionEvent class is in the java.awt.event package, and it has two methods, either of which you can use:

I strongly recommend that you get the applet working first, then worry about its appearance. Remember that the AWT is fairly primitive. You can choose your layout managers, but you can't tell them what to do. "Not too ugly" may be the best you can achieve. Don't spend a lot of time on appearance and leave "making it work" to the last minute. Functionality is more important than appearance.

Grading:

I expect most students will get 100 on this project. If your applet is particularly nice looking or particularly ugly, you might gain or lose a few points. You can earn some extra credit by adding functionality to the calculator--but do not change its essential nature. It must remain integer only, AWT only, and it must support the given bases.

Red tape: