Due in the
class on Tuesday 18th of April 2000 | |
Late submissions are not accepted | |
You can discuss this homework with others, but the submitted code must
be yours | |
Write
and test the following Java programs and submit a hardcopy of your source
code. Each program must be printed on a separate page. Don’t forget to
write your name and registration number. |
Create a class with public, private, protected, and "friendly" data members and method members. In a second Java source file, create an object of this class and see what kind of compiler messages you get when you try to access all the class members. Be aware that classes in the same directory are part of the "default" package. Submit your source code of the two Java files and the compiler messages.
Create the following file in one directory:
package C05;
class PackagedClass {
public PackagedClass () {
System.out.println("Creating a packaged class");
}
}
Then create the following file in another directory:
package C05.foreign;
import C05.*;
public class Foreign {
public static void main (String[] args) {
PackagedClass pc = new PackagedClass();
}
}
Explain why the
compiler generates an error. Would making the Foreign class part of the C05
package change anything?
A) Using the
AlarmClock class (which was presented in the 9th of April lecture), construct an
applet that displays a circle, the circle should periodically change size. The
circle's diameter should change as a triangular waveform.
B) Using the AlarmClock class, construct an applet that displays a ball that
bounces between two walls.
Modify the
ClickMe applet so that it stores the positions of 10 spots in an Stack object
(the Stack class was presented in a previous lecture). After the 10th click, the
applet should display all the ten spots.