public class OnlineNewsStory extends NewsStory
A OnlineNewsStory
is composed of the date snapshot of the story
was taken, the part of the day when the snapshot happened, the name of
the online news site that published the story, the length the story in words,
the broad topic for the story, the specific subject matter of the story, and
two lead news makers in the story.
Since most of these elements are present in NewsStory
,
OnlineNewsStory
is created as a subclass of
NewsStory
. However, OnlineNewsStory
can implement
getLengthInWords
because we know the inherent length measurement
units for online news stories (words), whereas different news stories may use
different length units. In addition, each OnlineNewsStory
includes the part of the day when the snapshot happened (morning or
afternoon), which isn't true for all types of NewsStory
. For
this reason, an additional field (partOfDay
) and corresponding
accessor and mutator methods are included in OnlineNewsStory
.
Modifier and Type | Field and Description |
---|---|
private PartOfDay |
partOfDay
The part of the day that the news story was captured (morning or
afternoon).
|
Constructor and Description |
---|
OnlineNewsStory(java.time.LocalDate date,
java.lang.String sourceName,
int length,
java.lang.String topic,
java.lang.String subject,
PartOfDay partOfDay,
NewsMaker newsMaker1,
NewsMaker newsMaker2)
The constructor which takes parameters for all of the fields can simply
pass most of them to the constructor for
NewsStory and let
it do most of the work. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object o)
Overridden equals method to account for possible differences in
partOfDay . |
int |
getLengthInWords()
Overrides the
getLengthInWords method from
NewsStory . |
PartOfDay |
getPartOfDay()
Accessor method that returns the part of the day when the capture
occurred.
|
void |
setPartOfDay(PartOfDay partOfDay)
Mutator method for the part of the day when the capture occurred.
|
compareTo, getDate, getLength, getNewsMaker1, getNewsMaker2, getSource, getSubject, getTopic
private PartOfDay partOfDay
public OnlineNewsStory(java.time.LocalDate date, java.lang.String sourceName, int length, java.lang.String topic, java.lang.String subject, PartOfDay partOfDay, NewsMaker newsMaker1, NewsMaker newsMaker2)
NewsStory
and let
it do most of the work. It only needs to handle partOfDay
itself.date
- The date the story was published as a java.time.LocalDate.sourceName
- The name of the source in which the story was published.length
- The length of the story.topic
- The broad topic of the story.subject
- The specific subject matter of the story.partOfDay
- The part of the day during which the story was captured.newsMaker1
- The first news maker featured in the story.newsMaker2
- The second news maker featured in the story.public int getLengthInWords()
getLengthInWords
method from
NewsStory
.
Because the inherent length measurement units for TV news stories are
seconds, we need to convert the value we get from getLength
.
The design says we should use the conversion factor of 150 words per
minute. (Of course, a minute is 60 seconds, so this is a conversion
factor of 150/60.)
getLengthInWords
in class NewsStory
NewsStory.getLengthInWords()
public PartOfDay getPartOfDay()
public void setPartOfDay(PartOfDay partOfDay)
partOfDay
- The part of the day when the capture occurred.public boolean equals(java.lang.Object o)
partOfDay
.
Note that we let the method in the parent do as much work as possible to reduce code duplication.