Question: Please read before posting an answer B. In the class BusRoutes add a field routes, which is a HashMap. Each key of the map will
Please read before posting an answer
B.
In the class BusRoutes add a field routes, which is a HashMap. Each key of the map will be an Integer representing a bus number, and each value an ArrayList of String objects representing names of places the bus stops on its route. Make this field public, for testing purposes.
Add a second private field reader of type InputReader.
C.
Copy the method populateRoutes from the README.TXT file included with the BlueJ project into your BusRoutes class. When invoked, this method will populate the routesmap with test data, so that each entry in the map consists of a bus number mapped onto an ArrayList that contains the names of stops, in the order at which they are visited, on that bus route.
Add a zero-parameter constructor to the BusRoutes class, which initialises routes to a new instance of HashMap. The reader field should be initialised to a new instance of InputReader, using the constructor in the InputReader class. Finally, the method populateRoutes should be invoked.
D.
Add a method with the header
public void printRoute(int busNum)
that prints the heading: "Bus number xxx route:" (where xxx is the received bus number) and then underneath, the list of stops, one per line, associated with busNum.
E.
Add a method with the header
public void printAllRoutes()
When this method is called, for each route, the bus number should be printed, followed by the list of all the stops for that bus number, each on a new line, then a blank line.
F.
Add a method with the header
public HashSet
that returns a HashSet containing all the bus numbers that have aStop on their route, or an empty HashSet if there are none.
G.
Add a method with the header
public HashMap
that returns a map derived from routes, in which each stop included in the routesmap is a key and each value is a set of bus numbers that have that stop on their route. There are marks in this part for reusing a method that you have previously written.
H.
Add a method with the header public void accessInfoService()
which prompts for input and produces output in the terminal window, as follows
Two blank lines are printed, followed by the welcome message on two lines:
"Welcome to the Bus Information Service."
"Type where you want to go to -> "
The user then enters a bus stop on the same line.
if there are no buses that stop at the stop.
The message "Sorry, no buses go there" is printed.
If there are buses that stop at the stop the following happens
A blank line is printed
The message "Here is a list of buses:" is printed
A blank line is printed
Each bus number that stops at that stop is printed, one per line.
A blank line is printed
The prompt "Enter bus number to get a full route -> " is printed
The user then enters a valid bus number on the same line
A blank line is printed
The message "Bus number xxx route:" is printed, where xxx is the entered bus number
Each stop on the route of that bus number is printed, one per line.
There are marks in this part for good reuse of one or more methods that you have previously written.
Notes:
Sample output has been provided in the file TMA02Q2SampleOutput.txt file that is in the TMA02Download folder.
You will also need to explore the Integer class in order to identify a static method that can be used to convert a String to a corresponding integer.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
