Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can you give me finished and working java codes please and can you create 3 different classes for bus busroute and busstop? Methods are explained
Can you give me finished and working java codes please and can you create 3 different classes for bus busroute and busstop? Methods are explained in the boxes.
\begin{tabular}{|l|} \hline \multicolumn{1}{|c|}{ Bus } \\ \hline busldentifier: String \\ driverName: String \\ capacity: int \\ passengers: int \\ speed: double \\ route: BusRoute \\ currentStop: BusStop \\ \hline + thankTheDriver(): void \\ + letPassengersOff(): int \\ + letPassengersOn(): int \\ + moveToNextStop(): double \\ + toString(): String \\ \hline \end{tabular} \begin{tabular}{|l|} \hline \multicolumn{1}{|c|}{ BusRoute } \\ \hline routeNumber: int \\ routeDescription: String \\ firstStop: BusStop \\ lastStop: BusStop \\ \hline + calculateDistance(): double \\ + toString(): String \\ \hline \end{tabular} \begin{tabular}{|l|} \hline \multicolumn{1}{|c|}{ BusStop } \\ \hline stopName:StringstopNumber:intxCoordinate:doubleyCoordinate:doublepassengersWaiting:int \\ + gainPassengers(): void \\ + losePassengers(numPassengers: int): boolean \\ + distance(other: BusStop): double \\ + toString(): String \end{tabular} passengers who got off the bus (should be all of them!) - letPassengersOn (2 pts): Lets as many passengers at current stop onto the bus that can fit on it without going over capacity. This should alter the currentStop object to reflect that waiting passengers have got on the bus. Returns the number of passengers who got on the bus. - moveToNextStop (2 pts): Moves this bus from its current stop to the other stop in its bus route (all bus routes have only two stops!). Uses the speed (in miles per hour) and the distance between the stops to calculate the time it took (in minutes) to travel. It returns this time as a double. - toString (2 pts): Returns a String representation of this object's state. Should at least include the busIdentifier, driverName, routeNumber of the route it's traveling on, current stop name, number of passengers, and capacity of the bus. BusRoute: - calculateDistance (2 pts): Calculates the distance between the first and last stops in the route (these are the only two stops in the route!) in miles. Returns this as a double. - toString (1 pts): Returns a String representation of this object's state. Should at least include the routeNumber and routeDescription BusStop: - gainPassengers (2 pts): Generates a random integer between 5 and 30 and adds this to the passengers waiting. This represents new people who have walked to the stop and joined the crowd waiting for a bus. - losePassengers (2 pts): Takes in an integer and removes this amount from passengers waiting, as long as it wouldn't cause passengers waiting to go negative. If the operation would cause passengers waiting to go negative, do not change passengers waiting. Returns true if the operation was successful, returns false if it was not. - distance (8 pts): Takes in another BusStop object, calculates the (Euclidean) distance between the input bus stop and this bus stop, returns that distance in miles. We're assuming the bus travels on a straight path from one stop right to the other, ignoring roads. To do this, you must use the Euclidean distance formula with the x and y coordinates of each stop. Assume x and y coordinates are given in miles from the center of the city
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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