Question
A bus route is represented by using a list of all bus stops on that route from source to destination inclusive. For example, the bus
A bus route is represented by using a list of all bus stops on that route from source to destination inclusive. For example, the bus route connecting Amman and Sult cities is a list of the following main bus stops: Amman, Swaileh, Beer-Albahsa, and Sult. Each route is a given a unique integer identification number. Write an ADT Route representing a bus route which should satisfy the following specifications:
1. [2] Immutable.
2. [2] Hides the abstraction barrier using a makeRoute method in the interface.
3. [3] Re-implements toString, equals, and hashCode.
4. [2] Provides a method interset which takes a Route object and returns a list of all shared bus stops.
5. [4] Demonstrate your solution by
- Create a route ID = 15, from Amman to Al-Sult, bus stops = [Shamal, Dakhliyya, Jordan University, Beer-Albahsa, Sult].
- Create a route ID = 20, from Raghadan to Jordan University, bus stops = [Raghadan, Dakhliyya, Jordan University].
- Print the route using toString method formatted as follows: ID: nn, Bus Stops: stop1, stop2, ..., last stop.
- Use the intersect method to find the shared bus stops of routs 15 and 20, and print these stops.
Step by Step Solution
3.39 Rating (158 Votes )
There are 3 Steps involved in it
Step: 1
Java Implementation of the same explained using comments import javautilArrayList declaring as final ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started