class NewspaperStoryList
extends java.lang.Object
A NewspaperStoryList
is a list of NewspaperStory
objects.
Modifier and Type | Field and Description |
---|---|
private java.util.ArrayList<NewspaperStory> |
newspaperStories
The list of newspaper stories.
|
Constructor and Description |
---|
NewspaperStoryList() |
Modifier and Type | Method and Description |
---|---|
void |
add(NewspaperStory newspaperStory)
The mutator for adding a newspaper story to the list.
|
NewspaperStory |
get(int index)
An accessor for getting a story from the list based on its position
(index) in the list.
|
int |
size()
The accessor for determining the number of stories in the list.
|
private java.util.ArrayList<NewspaperStory> newspaperStories
public void add(NewspaperStory newspaperStory)
By using our own class with its own add
method, rather than
directly using the add
method of ArrayList
, we
could ensure that we don't add duplicate NewspaperStory
objects to our 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.public int size()
Note that this accessor name violates the convention that accessor names should start with "get" (or "is" for booleans). However, "size" is an accepted convention for names serving this particular purpose, so we are following the second convention rather than the first.
public NewspaperStory get(int index)
index
- The location from which to get the story.java.lang.IllegalArgumentException
- if the index is not valid.