Homework #7 | CMSC 131 |
Due March 30th, 2003 | Object-Oriented Programming I |
Spring 2004 |
This homework will give you an opportunity to design some more complicated logic, and to get practice writing testing code. You will be graded as follows:
You will write a program that implements the logic of an interactive calculator along with testing code that tests your logic. A visual interface is supplied to you, so you can also hook up your logic to the interface and have an interactive calculator (see figure below).
The calculator must function according the following rules:
The following table shows button clicks and what must be shown in the display:
Button | Display |
2 | 2 |
+ | 2 |
5 | 5 |
= | 7 |
- | 7 |
3 | 3 |
- | 4 |
3 | 3 |
= | 1 |
/ | 1 |
0 | 0 |
= | Divide by zero |
5 | 5 |
7 | 57 |
+ | 57 |
2 | 2 |
3 | 23 |
= | 80 |
C | 0 |
We will be using CVS with AutoCVS as we have for previous assignments. You can access the assignment code by checking it out from CVS with Eclipse (it is called 'hw7'). You can read the API documentation here.
Your solution must create the Calculator class which implements the CalculatorMVC interface. CalculatorMVC requires you to follow a simple model-view-controller pattern as in the previous project. You are free to add instance variables and methods to the Calculator class as you see fit.
In addition, you must modify the supplied class called CalculatorTester to test your implementation. The testing program supplied tests the example shown in the table above, but you must write at least 10 more tests to evaluate all features of your calculator.
The constructor for your Calculator class must have the signature:
public Calculator();
Calculator also must implement these two methods (as defined in CalculatorMVC):
public String getDisplayString();
getDisplayString() gets called by CalculatorFrame immediately after keyClicked() is called and the returned string is shown in the calculator GUI. In addition, getDisplayString() is called once on startup after setCalculatorMVC() is called.
public void keyClicked(char key);
keyClicked() is called by CalculatorFrame immediately after any button in the calculatorGUI is pressed.
You should invoke your calculator from a main method as follows. By doing it this way rather than including the CalculatorFrame code in the Calculator constructor, you can write the CalculatorTester class which tests your calculator without using the GUI.
static public void main(String[] args) {
Calculator calc = new Calculator();
CalculatorFrame frame = new CalculatorFrame("Calc");
frame.setCalculatorMVC(calc);
}
Submit your program by right-clicking on your project and select "Submit Project". Note that this option will only appear if you have successfully installed AutoCVS as described previously. If you decide that you would like to make a change after you have submitted your project, you can resubmit as many times as you like before the extended deadline. We will grade the last project submitted.
/* Name * Student ID * Homework #7 */ <your code goes here> |
This is an "open" assignment. You are free to get whatever help you want to get this assignment done. You may look on the web, and talk to friends. You can even look at other student's solutions or have other students help you debug your code. But there are two conditions:
You must document all outside help you get in your timelog. If you have any non-trivial interaction with anyone about this homework, you must describe it (i.e., "<student xxx> helped me debug my program for 2 hours"). You will not be penalized for this help, but we want to know how much help people are getting to do this work - and we want you to be explicitly aware of how much help you are getting.
You are responsible for understanding the code you turn in. We expect you to know what you did as if you did it entirely privately. You need to be able to do this level of work at this point in the semester if you expect to succeed in following projects and in exams.
Change your getDisplayString() method to display all numbers with US formatting where every 3rd digit (counting from the right) is separated by a comma. So, instead of displaying "12345", you should display "12,345". You should use the java.lang.StringBuffer class to construct the string. You should read the Java API docs to learn about this class.