
CISC 370 Lecture Notes for Class No. 2, February 10, 2000

| Course Home | Prev Lect | Next Lect | Example Programs | Exercise Solns | CoreJava Progs Documentation |
Gen'l Docs | Java 2 APIs | Java Glossary | Term Proj Info |
1. (a) Copy the file example-progs/helloworld/HelloWorld.java to one of your directories.
(b) Alter the class HelloWorld to create a class Delaware that is an applet that prints the word "Delaware" in gold (or yellow) letters on an oval that has a blue background. Make the border around the oval black.
The solution directory .
(c) The third part of this exercise is designed to help you start becoming familiar with using the Java documentation - either the online documentation or Java in a Nutshell. Put the answers to the questions below in the comments of your program. Give a function prototype for the method Graphics.drawOval(). To which class does the method belong. What is the difference between the methods drawOval and fillOval().
To reach the online documentation, click the "Java 2 API" button at the top of a page. To find answers to questions like the ones above, use the index when you get to the Java 2 API web site. To use Java in a Nutshell, look in the index for the method names.
2. (a) What does the word "deprecated" mean in the Java context. Use either the Java Glossary or your textbook to answer this question. (b)What is the total number of public constructors in the class String? How many are deprecated?
| One day late | = |   penalty of 1 point |
| Two days late | = |   penalty of 3 points |
| Three days late | = |   penalty of 6 points |
| Four or more days late | = |   no credit. |
The clock ticks forward one day each day at 12:30PM, the beginning of class hour.
Note the minor problems with the fonts that occurs when using eXceed to demo this example.
First, a non-object-oriented C++ program for generating random sentences . This program is in the file $CISC370HOME/example-progs/randomSentences/c++/RandomSentences.cc.
Now a Java random sentence generator that mimics the C++ program and is not object-oriented. This program is in the file $CISC370HOME/example-progs/randomSentences/java/RandomSentences.java .
Thirdly, a Java object-oriented version of the program that uses the newly defined class RandomSentMachine that implements a random sentence generating machine that has a public interface similar to the interface for the "standard" class java.util.Random. This program is in two files. The file $CISC370HOME/example-progs/randomSentences/java/RandomSentMachine.java contains the definition of the class RandomSentMachine that defines an object (or machine) that generates random sentences. The second file, $CISC370HOME/example-progs/randomSentences/java/RSMachineTester.java contains a main method that implements a simple driver for testing the RandSentMachine class.
What makes this code object-oriented and the others non-OO? The focus in object-oriented programming is on the nouns in the problem description whereas in the older programming style the emphasis was on the verbs.
So in the OO version, we think of implementing a machine for generating random sentences. If we think of this machine as a physical object (and this is often a good way to think about OO design), we want to have a "button" on it that when depressed causes the machine to generate another random sentence. To make this machine, we realize that we need a random number generating machine. So we order a "Sentium" random number chip from "Outel" that we use as a component inside our machine. :)
When we implement our "machine" as a class, the components like the Sentium chip become instance variables (RNMachine in our RandomSentMachine class) that are assigned an object of the required type (a Random object in this case). "Buttons" are a part of the public interface of the object and are implemented as public methods (if the class had a graphics user interface, we might have such a button). We call our method nextSent() so that it will be analogous to the nextInt()( method in the class java.util.Random. A fancier "machine" for generating random sentences would have more "buttons" (public methods).
All of these programs are in the directory CISC370HOME/example-progs/randomSentences/ .
Back to the
CISC 370 homepage.
This page has been accessed
times since 9 Feb 2000.
Corrections, suggestions and comments to Bob Caviness
Copyright
2000 B. F. Caviness