



|
|
Byron's CSC212 Web Site
|
Class Notes
Monday November 27 , 2000
|
|
|
Notes on Superficial Signature and the Dictionary Class Program.
Class Notes --
Monday November 27 , 2000
CSC212 - November 27, 2000
========================
Lecture Topic: SUPERFICIAL SIGNATURES
DEF: The "Superficial Signature" of a Java program
fragment is the fragment with:
1. All literals replaced (constants) by their type
in angular brackets.
2. All objects referenced by variables replaced by
the type of the object in angular brackets.
Ex: int x = 5;
double y = 3.5;
double p = x * y;
IO.println("The product is " + p);
The Superficial Signature:
int x = <int>;
double y = <double>;
double p = <int> * <double>;
IO.println(<String> + <double>);
Ex: Circle c = new Circle (10);
Square s = new Square(10.0);
double aa = (c.area() + s.area())/2.0;
SS: Circle c = new Circle (<int>);
Square s = new Square (<double>);
double aa = (<Circle>.area() + <Square.area())
/<double>;
Ex: String beat = "quarter";
SS: String beat = <String>;
Ex: int bpm = 3'
SS: int bpm = <int>;
Ex: TimeSignature ts = new TimeSignature(beet,bpm);
SS: TimeSignature ts = new TimeSignature
(<String>,<int>);
Ex: ts.establish();
SS: <TimeSignature>.establish();
Ex: Scale s = new Scale (
SS: Scale s = new Scale (<String>,<String>)
Ex: Note x = new Note();
SS: Note x = new Note(<Scale>);
Dictionary Class - Program
// Instantiate - Give values
package white.words;
library class
public class Dictionary
// Constructors - Instantiate the Instance variables.
// Give values to instance variables
public Dictionary (String a)
{
name = s;
words = new Word(LIMIT); //LIMIT=Constant,all caps
nrElements = 0;
}
// Instance methods
public void add(Word w)
{
--------
}
Dictionary d = new Dictionary("Animals")
________________________________
| ____________ |
Picture | Name |____________| |
| ____________ |
| nrElements |____________| |
| ____________ |
| Words [0] |____________| |
| Words [1] |____________| |
| Words [2] |____________| |
| ... |____________| |
| ... |____________| |
| Words [999] |____________| |
|________________________________|
Adding Words to Dictionary:
## d.add("aardvark")
Add Method 1:
String[] s = new String [2];
s[0] = "aard";
s[1] = "vark";
word a = new Word("aardvark",s);
d.add(a);
Add Method 2:
public void add(String a)
{
IN in = new IN(s);
int nrWords = in.read_int();
for (int i=0; i < nrWords ; I++)
// IN
=========================================================
123456789112345678921234567893123456789412345678951234567
|
|
|