Make It a Double...Calculator Lab Part 3 - Making It Work

Due Date: Monday April 10, 2000 at 8:00 am

*Jim's Sample Solution! *Justin's Sample Solution! *Janice's Sample Solution! *Sonia's Sample Solution! *Formatted Real Numbers Example *


Overview for Labs 9, 10, & 11:
You are going to build a calculator of some type. We hope you don't resort to the standard and boring four function (+, - , x, /) calculator but something from your field of study. The rules are fairly simple:
- There must be at least five interactive widgets of your choosing
- At least one must be in input widget where the user enters the needed information
- At least one must be an output widget where the results of your calculation are displayed
- At least one must be a button that in some way affects the calculation

This only totals three so you will need multiples of some or all of the widget types.

Assignment:
Add the calculation engine. To do this you will need to add actionListeners for each Button object and add a new method called actionPerformed(ActionEvent e). Follow the instructions given in class to do this part.

Then you will need to use your new computer arithmetic skills to do the actual computation and report the results.

Background
If you get this working correctly, you can now think about getting fancy, or you can go out and enjoy the spring weather of Pittsburgh...

You will need to convert the text that represents the numbers typed in by the us er into real numbers. Java has several different types of real numbers. We wil l use the type double. Widgets objects of the class TextField have a method cal led getText() that retrieves the text entered by the user. It is retrieved as t ext even if the input is all digits. That text is retrieved as a String object. The TextFields shown below are called inpt1 and input2. To convert the text entered by the user you will need to add this method to your applet:
public double parseDouble(String s)
{
// note these are upper case 'D' 's on the next line
Double temp = Double.valueOf(s);
return temp.doubleValue();
}
The variable, num1 and num2 are of type double (lower case 'd'). To call this m ethod you will use code similar to this:
num1 = parseDouble(inpt1.getText() );
num2 = parseDouble(inpt2.getText()

Handin Instructions:
Create a folder named according to the tradition of the first seven labs. Put the .html and .java file into that folder. DO NOT HAND IN THE .class FILE!


FTP your folder to the usual place. Look for a folder marked Lab11.


15-120 Spring 2000                                                                   Lab 11

Back to 15-120 Assignments