CIS 121 February 7, 2000
Recall Programming Assignment 2.
You may use the following files to test your program.
Dictionary
Elementary
File
High
School
College
Comments about the program.
There are several methods available in the String object that you
may find useful. Let string be a String object.
- string.length() returns the length of the string.
- string.endsWith(s) returns a boolean value of true if string ends with s.
- string.substring(n) returns a substring of string beginning at 0 and ending at position n.
- string.substring(n,m) returns a substring beginning at position n and ending at position m.
- string.replace(char1,char2) replaces all instances of char1 in string with char2.
- string.toUpperCase() returns a string in which each letter is replaced by its uppercase equivalent.
Keep in mind that when the StreamTokenizer works, it considers words at the
end of sentences as strings. That is, it includes the period. You can use two of the
above methods to eliminate the period. Do not worry about other punctuation.
Another problem you will face is that of repeated words. In most files, there are
words that are repeated. This is important in the dictionary, but also
in the files that you read because you want to keep an accurate count
of valid words.
Recall that the dictionary should have no more than 250 words, and the
files should have no more than 350 tokens. You do not necessarily have to
limit the file, you just need to use a counter. In the sample files provided
you will need to use a counter because they are larger than our requirements.
Recall the important concepts we have discussed.
Inheritance - Using the extends clause to create new classes that inherit methods
and variables from other classes.
Polymorphism - Making method calls through different forms.
Other notes about the Object class
- Contains a method toString that is public with return type String and
an empty parameter list that defines how a object is treated if it is used
in the context of a string.
- Contains a method called equals which allows us to compare it to other
objects.
Concrete Method - Methods which have implementations.
Concrete Classes - Classes in which all methods are concrete.
Abstract Method - Methods which have no implementation.
Abstract Classes - Classes in which at least one method is abstract.
One correction about how an abstract method is defined. Instead of
using { ... }, use an ;. For example, int number(int a);
Another statement we can have in a class definition is an implements clause.
We use this to implement interfaces. Interfaces contain only abstract methods
and interface constants.