Homework 5

Due Thurs. Nov 25, 18:00

Exercise:

part 1 (8 points)


A lexical unit contains information about a word. What information it contains depends on how it is intended to be used. Often it contains the various orthographic forms (spellings), the POS (part-of-speech), a definition, example sentences, information about relationships to other words (synonyms, antonyms,...). Since this is one of our first class definitions, we'll just include the orthographic forms and synonyms for now.

Define a class called LexUnit to represent a lexical unit with orthographic forms (also referred to as orthForms, or just forms) and synonyms, described by the UML diagram:

LexUnit

-  orthForms : String
-  synonyms : String
-  numOrthForms : int
-  numSynonyms : int


+ initialize() : void
+ getOrthForms() : String
+ getSynonyms() : String
+ getNumSynonyms() : int
+ getNumOrthForms() : int
+ addOrthForm(String aForm) : void
+ addSynonym(String aSynonym) : void
+ toString() : String



Method descriptions:

public void initialize()
Initialize the instance variables so that the LexUnit
has no orthForms and no synonyms
public String getOrthForms()
Return the orthforms for this LexUnit
public String getSynonyms() Return the synonyms for this LexUnit
public int getNumSynonyms() Return the number of synonyms for this LexUnit
public int getNumOrthForms()
Return the number of orthForms for this LexUnit
public void addSynonym(String aSynonym) Add aSynonym to this LexUnit's synonyms
public void addOrthForm(String aForm) Add aForm to this LexUnit's orthForms
public String toString()
Generate and return a String containing the number of orthforms,
the orthforms, the number of synonyms, and the synonyms


Additional requirements:


part 2 (2 points)

Now write a program called LexUnitDemo that creates 3 LexUnit objects, initializes them, adds orthForms and synonyms, and prints all 3.  You do not need to get data from the user - just create and fill the LexUnits with values of your choice from within the demo program.  If you implemented the toString method correctly you should be able to print a LexUnit called lex1 with one of the following print statements:

// println method automatically calls the
// toString method of lex1
System.out.println(lex1);

// this does the same thing, but calls
// toString directly:
System.out.println(lex1.toString());

Sample LexUnitDemo output:

I created 3 LexUnits:

orthForms (2):  realize realise
synonyms (3):  recognize understand see

orthForms (2):  theater theatre
synonyms (1):  playhouse

orthForms (2):  color colour
synonyms (4):  dye pigment tinge tint


Submit the following files to Anne (javaiscl (at googlemail.com)):
LexUnit.java
LexUnitDemo.java