class UserInterface
extends java.lang.Object
This class provides helper methods to interact with the user.
Note that all methods in this class are static because we don't need to make
several UserInterface
objects and have them maintain their own
data. Instead, we simply need a collection of useful methods to create
windows that pop up one at a time, are used, and then are discarded.
Constructor and Description |
---|
UserInterface() |
Modifier and Type | Method and Description |
---|---|
private static java.lang.String |
convertToOutputFormat(NewsStory newsStory,
java.lang.String mediaType)
This method converts an individual story to the desired display format.
|
static java.lang.String |
createListOfNewsStoriesForNewsmaker(NewsMaker newsMaker,
java.lang.String mediaType,
java.lang.String[] sortCriteria)
This method takes a news maker and turns its list of news stories into a
String formated for display to the user. |
static void |
presentNewspaperStories(java.lang.String listOfStories,
java.lang.String newsMakerName)
This method displays the list of news stories to the user at the console.
|
static boolean |
queryBoolean(java.lang.String message)
This method prompts the user (at the console) with whatever message is
passed in through the parameter
message , followed by the
String " (y/n)?". |
static java.lang.String |
queryFileName(java.lang.String message)
This method prompts the user (at the console) with whatever message is
passed in through the parameter
message . |
static java.lang.String |
queryMatchType()
This method asks the user (at the console):
"Search news makers by exact or partial matches (e or p)? " The method loops until a valid answer in given. |
static java.lang.String |
queryMediaType()
This method asks the user (at the console):
"Search newspapers, TV news, or both (n, t, or b)? " The method loops until a valid answer in given. |
static java.lang.String |
queryNewsMakerName(java.lang.String matchType)
This method asks the user for the name of a news maker using console
input and returns it.
|
static java.lang.String |
querySortCriterion(java.lang.String sortCriterion)
This method asks the user (at the console) for a sort criterion.
|
static void |
reportNewsmakerNotFound(NewsMaker queriedNewsMaker)
This method reports at the console that there were no relevant stories
found.
|
public static java.lang.String queryMediaType() throws java.io.IOException
java.io.IOException
- If something goes wrong reading a line from the console.public static java.lang.String queryMatchType() throws java.io.IOException
java.io.IOException
- If something goes wrong reading a line from the console.public static java.lang.String queryNewsMakerName(java.lang.String matchType) throws java.io.IOException
matchType
, which has "e" and "p"
as its two valid options.matchType
- Whether the name match will be exact (e) or partial (p).java.io.IOException
- If something goes wrong reading a line from the console.public static java.lang.String querySortCriterion(java.lang.String sortCriterion) throws java.io.IOException
String
(""), it will ask about the
primary sort criterion. If called with a non-empty String
,
it will ask for a secondary sort criterion that isn't the sort criterion
passed in as a parameter. The method loops until a valid answer in given.sortCriterion
- The primary sort criterion already specified by the user (if
any).java.io.IOException
- If something goes wrong reading a line from the console.public static java.lang.String queryFileName(java.lang.String message) throws java.io.IOException
message
. This message is
intended to ask for filenames but does no checks on the
String
returned so it could be used to ask any question that
takes a String
as a response.message
- The message with which to prompt the user.java.io.IOException
- If something goes wrong reading a line from the console.public static boolean queryBoolean(java.lang.String message) throws java.io.IOException
message
, followed by the
String " (y/n)?". This message is intended to ask questions to which the
answer should be yes (y) or no (n) and it returns a boolean value of
true
or false
, respectively. The method loops
until a valid answer in given.message
- The message with which to prompt the user.java.io.IOException
- If something goes wrong reading a line from the console.public static java.lang.String createListOfNewsStoriesForNewsmaker(NewsMaker newsMaker, java.lang.String mediaType, java.lang.String[] sortCriteria)
String
formated for display to the user. At the end it
includes a line summarizing the number of stories found, the number of
different news sources in which these stories were published, the total
length of these stories, and the number of different topics found.
The summary line will have a slightly different format depending on media type specified.
newsMaker
- The news maker for which to create the story list as a string.mediaType
- The type of media (newspaper, TV news, or both, given as n, t,
or b) that should be included in the list.sortCriteria
- The primary, secondary, and tertiary sort criteria to use
(source, topic or length, given as s, t, or l), in an array
where element 0 corresponds to primary, 1 to secondary, and 2
to tertiary.private static java.lang.String convertToOutputFormat(NewsStory newsStory, java.lang.String mediaType)
The returned line will have a slightly different format depending on media type specified.
newsStory
- The story to convert to the display format.mediaType
- The type of media (newspaper, TV news, or both, given as n, t,
or b) that will be included in the list.public static void presentNewspaperStories(java.lang.String listOfStories, java.lang.String newsMakerName)
listOfStories
- The list of stories to display, all as one (potentially very
large) String.newsMakerName
- The name of the news maker (which is put into the title of the
JOptionPane).public static void reportNewsmakerNotFound(NewsMaker queriedNewsMaker)
"There are no relevant stories about news maker in this database."
queriedNewsMaker
- The news maker the user searched for.