class NewsMaker
extends java.lang.Object
A NewsMaker
is the subject of a NewspaperStory
. A
NewsMaker
may be a person or an organization. A
NewsMaker
consists of a name and a collection of newspaper
stories that feature that NewsMaker
. There is a special
NewsMaker
with the name "None" that is used for newspaper
stories that don't have at least two named NewsMakers
.
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
name
The name of the news maker.
|
private NewspaperStoryList |
newspaperStories
The list of newspaper stories in which the news maker is featured
|
Constructor and Description |
---|
NewsMaker()
The no-argument constructor for the class.
|
NewsMaker(java.lang.String name)
The general constructor for the class which takes the name of the news
maker (generally the only thing we know about a news maker when the
constructor is called) as an argument.
|
Modifier and Type | Method and Description |
---|---|
void |
addNewspaperStory(NewspaperStory newspaperStory)
The mutator that adds a newspaper story to a news maker's list of
stories.
|
boolean |
equals(java.lang.Object o)
An overridden
equals method. |
java.lang.String |
getName()
The accessor for the name field.
|
NewspaperStoryList |
getNewspaperStories()
The accessor for the list of newspaper stories.
|
private java.lang.String name
private NewspaperStoryList newspaperStories
NewsMaker()
public NewsMaker(java.lang.String name)
name
- The name of the news maker.public boolean equals(java.lang.Object o)
equals
method.
A NewsMaker
should be equal to another object if that object
is also a NewsMaker
object and they have the same name.
(Since equals
is a method in the Object
class
that we are overriding, the parameter needs to be an
Object
.)
equals
in class java.lang.Object
o
- The Object to which to compare this.public java.lang.String getName()
Note that String
objects are immutable, so it is fine to
return the field itself.
public NewspaperStoryList getNewspaperStories()
Note that NewsPaperstoryList
objects are mutable, so this
really should return a copy of the list instead. However, we haven't
studied that yet, so returning the list itself is acceptable for now.
public void addNewspaperStory(NewspaperStory newspaperStory)
Note that since this list should contain only stories in which the news
maker is featured, we should have this method verify that the
NewsMaker
object is referenced in the
NewspaperStory
object before the story is added to the list.
However, to keep the project relatively simple, this requirement was not
made in the project description and this check doesn't need to be made
yet.
newspaperStory
- The newspaper story to add.