Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you give me finished and working java codes please and can you create 3 different classes for train metroroute and metrostop? Methods are explained

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Can you give me finished and working java codes please and can you create 3 different classes for train metroroute and metrostop? Methods are explained in the boxes.

\begin{tabular}{|l|} \hline \multicolumn{1}{|c|}{ Train } \\ \hline trainldentifier: String \\ conductorName: String \\ cars: int \\ passengers: int \\ speed: double \\ route: MetroRoute \\ currentStation: MetroStation \\ + thankTheConductor(): void \\ + calculateCapacity(): int \\ + letPassengersOff(): int \\ + letPassengersOn(): int \\ + moveToNextStation(): double \\ + toString(): String \\ \hline \end{tabular} \begin{tabular}{|l|} \hline \multicolumn{1}{|c|}{ MetroRoute } \\ \hline routeNumber: int \\ routeDescription: String \\ firstStop: MetroStation \\ lastStop: MetroStation \\ \hline + calculateDistance(): double \\ + toString(): String \\ \hline \end{tabular} MetroStation stationName: String stationNumber: int xCoordinate: double yCoordinate: double passengersWaiting: int + gainPassengers(): void + losePassengers(numPassengers: int): boolean + distance(other: MetroStation): double + toString(): String Train: - thankTheConductor (1 pt): Print a String to console that thanks the train conductor for their hard work 2 - calculateCapacity (1 pt): Uses the number of cars on the train to calculate its capacity. As a rule, each train car can hold 120 people. - letPassengersOff (2 pts): Lets all of the passengers off the train. Returns the number of passengers who got off the train (should be all of them!) - letPassengersOn (2 pts): Lets as many passengers at the current station onto the train that can fit on it without going over capacity (you'll have to calculate this capacity...). This should alter the currentStation object to reflect that waiting passengers have got on the train. Returns the number of passengers who got on the train. - moveToNextStation (2 pts): Moves this train from its current station to the other station in its route (all metro 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 trainIdentifier, name of the conductor, route number it's traveling on, station name where it's currently stopped, number of passengers, and capacity. MetroRoute: - calculateDistance ( 2 pts): Calculates the distance between the first and last stations in the route (these are the only two stations 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. MetroStation: - gainPassengers (2 pts): Generates a random integer between 20 and 200 and adds this to the passengers waiting. This represents new people who have walked to the station and joined the crowd waiting for a train. - 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 MetroStation object, calculates the (Euclidean) distance between the input metro station and this station, returns that distance in miles. We're assuming the train travels on a straight path from one station right to the other. To do this, you must use the Euclidean distance formula with the x and y coordinates of each station. Assume x and y coordinates are given in miles from the center of the city. - toString (2 pts): Returns a String representation of this object's state. Should at least include the stationNumber, stationName, and passengers waiting at this station

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

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago