Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Train Member Variables: next: Train prev: Train trainNumber: int destination: String arrival Time: int transfer Time: int Constructors: + Train() Track Getters/Setters: All member variables

image text in transcribedimage text in transcribedimage text in transcribed

Train Member Variables: next: Train prev: Train trainNumber: int destination: String arrival Time: int transfer Time: int Constructors: + Train() Track Getters/Setters: All member variables as necessary. Methods: set Next (next Train: Train) : void setPrev(prevTrain Train) : void getNext(): Train getPrev(): Train equals(obj: Object) : boolean toString(): String Member Variables: head: Train tail: Train cursor Train next Track prev: Track utilizationRate: double trackNumber: int Constructors: + Track() Station Getters/Setters: All member variables as necessary. Member Variables: head: Track tail: Track cursor: Track Constructors: + Station) Methods: addTrain(newTrain: Train) : void + printSelectedTrain(); void + removeSelectedTrain() : Train + select Next Train() : boolean + Select Prev Train()boolean + tostring() String Getters/Setters: All Member variables as necessary. Methods: addTrack(newTrack: Track) : void removeSelected Track(): Track printSelected Track()void printAllTracks) void select Track(trackToSelect: int) : boolean toString() String Static Methods: + main(args: String[]) : void Write a fully-documented class named Train that contains basic information for a train approaching a station. Required information includes the train number, the train's destination, the arrival time of the train to its track (in 24-hour format between 0000 - 2359), and the transfer time for how long the train waits at the station in minutes). You may add additional fields as needed. The following is a partial specification and it is up to you to fill in the details: public Train() o Constructor for Train (you may include an additional constructor with parameters) public void setNext(Train next Train) o Sets the next Train in the list. O NOTE: The next Train should point to the train scheduled to arrive after this one. There can be a gap in time between the departure of this train and the arrival of the next one, but there shouldn' be another train in between this train and its pointer to the next train. public void setPrev(Train prevTrain) o Sets the previous Train in the list. NOTE: Similar to the last note, the previous train should be the train arriving before this train. There shouldn't be a train between this train and its pointer to the previous train. public Train getNext() o Returns the next Train in the list. If there is no next Train, returns nuli. public Train getPrev() o Returns the previous Train in the list. If there is no previous Train, returns null. public boolean equals(Object o) o Check if this Train object is equal to the supplied parameter. O NOTE: Two Train objects are considered equal if and only if their Train numbers are equal. public String toString() Returns a textual representation of all the information for this Train object. See sample I/O. Getters/Setters for all fields as necessary. 2. Track Write a fully-documented class named Track that contains references to the head and tail of a list of Train nodes, as well as a cursor representing the selected Train node. You also want to keep in mind the Track utilization rate for what percentage of the day the track is being used (total time of trains waiting at the track/total minutes in a day). Each track also contains a track number, which must be unique among all Track objects (there can only be one 'Track 1'). The Train objects stored in your Track must be sorted according to the arrival times of the trains. Your class will follow this specification, but you have to fill in the details: public Track() o Constructor for Track (you may include an additional constructor with parameters). public void addTrain(Train newTrain) o Adds a new Train to the specified Track list. After insertion, the currently selected train for this Track object should be updated to be the newly inserted Train. o NOTE: Since we are using a 24-hour time format, the last possible time a train can depart is at 2359 hours and the earliest a train can arrive is at 0000 hours. The Track list is ordered by time, where the head node should be the train to arrive at the station first, and the tail node should be the train to depart from the station last. The user inputs the arrival time in proper 24- hour time format (e.g. do not accept 0070, but do accept 0110) and transfer time in minutes (which is used to calculate the departure time which is also in valid 24-hour time format). O NOTE: You do NOT need to handle the case where a Train arrives one day and leaves the next. e.g., a Train can not arrive at 2345 and depart at 0015. O NOTE: Make sure that two trains can't be scheduled for the same track at the same time. If the user tries to input an arrival and departure time that conflicts with an already scheduled train, alert the user that the train could not be scheduled. O NOTE: Make sure that a Train can not be scheduled if it has the same train number as an already scheduled Train in the same track. o HINT: There are 1440 minutes in a day. public void printSelectedTrain() o Prints the data of the selected Train. public Train removeSelectedTrain() o Removes the selected Train from the track and returns a reference to it. If there is no Train selected, return null. o The selected Train should now be the Train node after the one which was just removed. If there is no Train after the one which was just removed, the selected Train should now be the node before the one which was just removed. If the Train removed was the only one in the Track list, then the selected Train should now be null. public boolean selectNextTrain() o Moves the reference of the selected Train node forwards to the next Train if it exists and returns true. If there is no next Train, then the selected Train should remain the same and return false. If there is no selected Train, you should throw an appropriate exception. public boolean selectPrevTrain() o Moves the reference of the selected Train node backwards to the previous Train if it exists and returns true. If there is no previous Train, then the selected Train should remain the same and return false. If there is no selected Train, you should throw an appropriate exception. public String toString() Returns a neatly formatted list of all the trains scheduled on this Track. See sample I/O. Getters/Setters for all fields as necessary. Train Member Variables: next: Train prev: Train trainNumber: int destination: String arrival Time: int transfer Time: int Constructors: + Train() Track Getters/Setters: All member variables as necessary. Methods: set Next (next Train: Train) : void setPrev(prevTrain Train) : void getNext(): Train getPrev(): Train equals(obj: Object) : boolean toString(): String Member Variables: head: Train tail: Train cursor Train next Track prev: Track utilizationRate: double trackNumber: int Constructors: + Track() Station Getters/Setters: All member variables as necessary. Member Variables: head: Track tail: Track cursor: Track Constructors: + Station) Methods: addTrain(newTrain: Train) : void + printSelectedTrain(); void + removeSelectedTrain() : Train + select Next Train() : boolean + Select Prev Train()boolean + tostring() String Getters/Setters: All Member variables as necessary. Methods: addTrack(newTrack: Track) : void removeSelected Track(): Track printSelected Track()void printAllTracks) void select Track(trackToSelect: int) : boolean toString() String Static Methods: + main(args: String[]) : void Write a fully-documented class named Train that contains basic information for a train approaching a station. Required information includes the train number, the train's destination, the arrival time of the train to its track (in 24-hour format between 0000 - 2359), and the transfer time for how long the train waits at the station in minutes). You may add additional fields as needed. The following is a partial specification and it is up to you to fill in the details: public Train() o Constructor for Train (you may include an additional constructor with parameters) public void setNext(Train next Train) o Sets the next Train in the list. O NOTE: The next Train should point to the train scheduled to arrive after this one. There can be a gap in time between the departure of this train and the arrival of the next one, but there shouldn' be another train in between this train and its pointer to the next train. public void setPrev(Train prevTrain) o Sets the previous Train in the list. NOTE: Similar to the last note, the previous train should be the train arriving before this train. There shouldn't be a train between this train and its pointer to the previous train. public Train getNext() o Returns the next Train in the list. If there is no next Train, returns nuli. public Train getPrev() o Returns the previous Train in the list. If there is no previous Train, returns null. public boolean equals(Object o) o Check if this Train object is equal to the supplied parameter. O NOTE: Two Train objects are considered equal if and only if their Train numbers are equal. public String toString() Returns a textual representation of all the information for this Train object. See sample I/O. Getters/Setters for all fields as necessary. 2. Track Write a fully-documented class named Track that contains references to the head and tail of a list of Train nodes, as well as a cursor representing the selected Train node. You also want to keep in mind the Track utilization rate for what percentage of the day the track is being used (total time of trains waiting at the track/total minutes in a day). Each track also contains a track number, which must be unique among all Track objects (there can only be one 'Track 1'). The Train objects stored in your Track must be sorted according to the arrival times of the trains. Your class will follow this specification, but you have to fill in the details: public Track() o Constructor for Track (you may include an additional constructor with parameters). public void addTrain(Train newTrain) o Adds a new Train to the specified Track list. After insertion, the currently selected train for this Track object should be updated to be the newly inserted Train. o NOTE: Since we are using a 24-hour time format, the last possible time a train can depart is at 2359 hours and the earliest a train can arrive is at 0000 hours. The Track list is ordered by time, where the head node should be the train to arrive at the station first, and the tail node should be the train to depart from the station last. The user inputs the arrival time in proper 24- hour time format (e.g. do not accept 0070, but do accept 0110) and transfer time in minutes (which is used to calculate the departure time which is also in valid 24-hour time format). O NOTE: You do NOT need to handle the case where a Train arrives one day and leaves the next. e.g., a Train can not arrive at 2345 and depart at 0015. O NOTE: Make sure that two trains can't be scheduled for the same track at the same time. If the user tries to input an arrival and departure time that conflicts with an already scheduled train, alert the user that the train could not be scheduled. O NOTE: Make sure that a Train can not be scheduled if it has the same train number as an already scheduled Train in the same track. o HINT: There are 1440 minutes in a day. public void printSelectedTrain() o Prints the data of the selected Train. public Train removeSelectedTrain() o Removes the selected Train from the track and returns a reference to it. If there is no Train selected, return null. o The selected Train should now be the Train node after the one which was just removed. If there is no Train after the one which was just removed, the selected Train should now be the node before the one which was just removed. If the Train removed was the only one in the Track list, then the selected Train should now be null. public boolean selectNextTrain() o Moves the reference of the selected Train node forwards to the next Train if it exists and returns true. If there is no next Train, then the selected Train should remain the same and return false. If there is no selected Train, you should throw an appropriate exception. public boolean selectPrevTrain() o Moves the reference of the selected Train node backwards to the previous Train if it exists and returns true. If there is no previous Train, then the selected Train should remain the same and return false. If there is no selected Train, you should throw an appropriate exception. public String toString() Returns a neatly formatted list of all the trains scheduled on this Track. See sample I/O. Getters/Setters for all fields as necessary

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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