|
These exercises illustrate various basic aspects of programming
with classes and objects.
- Create an applet with two parameters in the web page tag consisting
of an integer and floating point value. Create an applet that
performs the following.
- The integer parameter takes one of three different values,
say 0, 1, and 2. Test on the integer parameter to decide which
of 3 different methods to call.
- Each of these methods should carry out a different calculation
with the floating point parameter.
- Print out a message from each method indicating the method
chosen and the result obtained.
- Create an application with two attached classes, e.g. Test1
and Test2,
in the file instead of the one class Test
as in the demos in this chapter. Test1
should contain a single method and Test2
just holds a single data variable.
Create an instance of each class in the main()
method. Call the method in Test1
with a reference to Test2
in the argument list. In that method, alter the value of the variable
in the Test2
object. When the process returns to main(),
print out the value of the Test2
variable.
- Create a static class with a method to calculate the area of
circle using the radius passed in the argument.
- For the WrapperApplet
demonstration program,
- Put in a non-number string in the applet tag for the first
parameter and run the applet.
- Re-write the applet to "catch" the error, print
a error message, and use a default value for "val1".
- Repeat for the second parameter, i.e. use a non-boolean
string in the applet's second tag, catch the error, and use
a default value.
|
|
|