CS1 Course Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
CS1 Course Site  
 
 
 
Wait , WAIT !!What's that word ? ( Class Notes ( without definitions ) )

Wednesday November 8 , 2000
 
import blue.cards.   *;
import < enterprice >.   < package >.   < class > (* for all);
Ex
import blue.cards.   *;
import white.words.   *;
note
Off the cs1 home page you will find documentation for the ``blue'' package. 

write an operator style method called iota which takes one positive integer as its sole parameter and returns the array of integers containing 1,  2,  3,  ...   ,  n where n is the parameter.
Ex
iota (5) -- > | 1 | 2 | 3 | 4 | 5 |
iota (1) -- > | 1 |
iota (9) -- > | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
static private int [] iota (int n)
{
    int a [] = new int [n]
    for (int x = 0;  x < n-1;  x + +)
    {
        a [x] = x + 1;
    }
    return a;
}
write anoperator style method which copies (i.e,  makes a copy of) an array of character strings.
static private String [] copy (String [] s)
{
    String c [] = new String [s.length];
    for (int i = 0;  i < s.length;  i + +)
    {
        c [i] = s [i];
    }
    return c;
}
Define a class caleed word which can be used to store Words in terms of...

  • the word
  • the syllables of the word
Java code for the class definition.
public class Word
{
    / /instance variables
      private String word;
      private String [] syllables;
    / /constructors
    / /the constructor will create a
    / /word by reading information
    / /from the standard input screen
    / /it will read...
  • / /the word
  • / /the number of syllables
  • / /the syllables
    / /today 2 to day
    / /examination 5 ex am
    / /in a tion
    public Word ()
    {
        word = IO.readString ();
        int nrSyllables = IO.read_int ();
        syllables = new String [nrSyllables];
\ttline         {
            syllables [x] = IO.readString ();
        }
    }
    / /Methods
    / /compute the length of the word
    / / (nr characters in the word)
    public int length ()
    {
        return word.length ();
    }
    / /compute the nr of syllables
    / /in the word
    public int nrSyllables ()
    {
        return syllables.length;
    }
}
Define a class which represents a named dictionary.
There will be two properties
  1. The name (String)
  2. The words (Word [])
public class Dictionary
{
/ /instance variables
    private String name;
    private Word [] words;
/ /Constructor # 1:   create an empty
/ /dictionary
    public Dictionary (String theName)
    }
        name = theName;
        words = new Word [0]
    }
/ /constructor # 2:   create a dictionary
/ /by reading elements (word entries)
/ /from the standard input file
/ /indicating the number of
/ /word entries.
    public Dictionary (String theName)
    {
        name = theName;
        int nrWords = IO.read_int ();
        words = new Words [nrWords];
        for (int i = 0;  i < nrWords;  i + +)
        {
            words [i] = new Word ();
        }
    }
}
Note
as things stand we can only use one of these two constructors