Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

.Launch BlueJ and open the project TMA02Q2 then immediately save the project as TMA02Q2SolXX, where XX should be replaced by your own initials, in the

.Launch BlueJ and open the project TMA02Q2 then immediately save the project as TMA02Q2SolXX, where XX should be replaced by your own initials, in the TMA02Download folder you unzipped earlier. This project contains the InputReader class that you should read but not modify (you saw something similar in the tech-support project in Chapter 6.)

Begin by adding a new class called BusRoutes. Retain the class comment but edit it to include your own name and the date and a description of the class BusRoutes. Remove the sample code. Include the appropriate import statements for HashMap, ArrayList and HashSet.

(5 marks)

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.

(5 marks)

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 routes map 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.

(5 marks)

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.

(5 marks)

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.

(5 marks)

f.Add a method with the header

public HashSet getBusesStoppingHere(String aStop)

that returns a HashSet containing all the bus numbers that have aStop on their route, or an empty HashSet if there are none.

(5 marks)

g.Add a method with the header

public HashMap> getStopsAndBusNumbers()

that returns a map derived from routes, in which each stop included in the routes map 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.

(10 marks)

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.

(10 marks)

i.Go back and check that you have provided Javadoc comments for your class, constructors and methods, including the @author, @version, @param and @return annotations where appropriate. Be sure that your comments explain the purpose of the code and identify which part of the TMA question you are answering in each case.

Also check that you have used a consistent style across the whole class. See the M250 Code Conventions and Design document for more advice on coding style and check that you reused methods in this question where possible rather than duplicating code.

(10 marks)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

Students also viewed these Databases questions