CSC 132 Fall 2000
Homework 3
Due: midnight, Monday 1 October 2000.
30 points
"Visual Poly"
Starting with IntArrayPoly.java (eccentric download folder):
- modify the Print method so it returns a String representing the polynomial rather than printing to the screen.
- write an interactive applet called PolyApplet.java (use BagApplet.java in the eccentric download folder as a pattern) to test the following methods: InsertTerm, getCoefficient, getMaxDegree, Evaluate, and Print. Details below.
The applet will create a GUI window that resembles the one from BagApplet, with components neatly arranged. Here are the GUI requirements:
- An appropriate introductory label.
- A button labeled "Instantiate" and a textfield for maxDegree with default value "10" (use setText method with String argument).
- A button labeled "InsertTerm" and two labeled textfields, one for coefficient and one for exponent.
- A button labeled "getCoefficient". It will share the exponent textfield with InsertTerm.
- A button labeled "getMaxDegree"
- A button labeled "Evaluate" and one textfield for evaluation point.
- A button labeled "Print"
- A textarea for system responses.
Initially, focus is on Instantiate's textfield and its default value 10 is selected. All buttons except Instantiate are disabled. A button is disabled by calling its setEnabled method with argument of false. For example, if the button object is PrintButton, then PrintButton.setEnabled(false); will disable (dim) it. All this initialization is done in the init method.
Every button click must generate an appropriate system response in the textarea. These are:
- For Instantiate, normal response is confirmation message with maxDegree value. Also, enable the other buttons (call the setEnable method with argument true). Error response is generated if invalid value is provided in the textarea.
- For InsertTerm, normal response is confirmation message that includes the values. Error response is generated if invalid values are entered (this includes exponent out of range).
- For getCoefficient, normal response is message containing the coefficient value. Error response is generated if invalid values are entered (this includes exponent out of range).
- For getMaxDegree, response is message containing the maxDegree value.
- For Evaluate, response is message containing the evaluation point and resulting value.
- For Print, response is the String returned by modified Print method.
The second constructor, InsertTerm and getCoefficient methods all throw the IllegalArgumentException exception. When you call them in your action listeners, wrap the call in a try block, then use a catch block to catch IllegalArgumentException's. The error message is then printed from your catch block, instead of causing the program to terminate!! There are examples of try-catch in BagApplet.java.
When finished, submit PolyApplet.java and IntArrayPoly.java to your eccentric upload folder.
[ Assignments | CSC 132 | Peter Sanderson | Computer Science | SMSU ]
Last reviewed: 20 September 2000
Peter Sanderson (
PeteSanderson@smsu.edu )