public class TVNewsStory extends NewsStory
A TVNewsStory
is composed of the date the story was broadcast,
the part of the day when the broadcast happened, the name of the TV
news show that broadcast the story, the length the story in seconds, 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
,
TVNewsStory
is created as a subclass of NewsStory
.
However, TVNewsStory
can implement getLengthInWords
because we know the inherent length measurement units for TV news stories
(seconds), whereas different news stories may use different length units.
In addition, each TVNewsStory
includes the part of the day
when the broadcast happened (morning, afternoon, evening, or late night),
which isn't true for all types of NewsStory
. For this reason, an
additional field (partOfDay
) and a corresponding accessor method
(getPartOfDay()
) is included in TVNewsStory
.
Modifier and Type | Field and Description |
---|---|
private PartOfDay |
partOfDay
The part of the day that the news story was broadcast (morning,
afternoon, evening, or late night).
|
Constructor and Description |
---|
TVNewsStory(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 for the part of the day when the broadcast occurred.
|
void |
setPartOfDay(PartOfDay partOfDay)
Mutator method for the part of the day when the broadcast occurred.
|
compareTo, getDate, getLength, getNewsMaker1, getNewsMaker2, getSource, getSubject, getTopic
private PartOfDay partOfDay
public TVNewsStory(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 broadcast.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 broadcast 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.