6
answers
0
watching
378
views
28 Sep 2018

7. Write a class MetroLine in which you define a new type MetroLine (10 points) A MetroLine is defined to have the following private properties: • A String representing the colour of the line (e.g. blue, red, green, etc. No numbers. It's Montreal, not Manhattan!) • A collection of MetroStation This collection can be either a built in array, an ArrayList, or any other kind of collection you feel would satisfy the requirements of the class. The collection must be able to define an ordering from "beginning" to "end" of the MetroLine. It does not matter which part you consider the beginning and which part is the "end" as long as it is consistent. (We recommend using ArrayList but you are free to do otherwise if you feel it will be casier.) A MetroLine should have the following methods defined: • A constructor which takes nothing as input and performs any initialization necessary to maintain your collection of stations. • A method addstation which takes as input a MetroStation and adds it to the end of your collection. The method can assume the station is not already part of the collection and should return void. Note that the order the MetroStations are added is the same as the path the trains will travel on (or it could be the reverse path as well). • A method hasStation which takes as input a MetroStation and returns a boolean representing whether the metro line has a MetroStation with the same name or not. A method get LineColour which returns the colour of the line. • A method get First Stop which returns the MetroStation representing the first stop of the metro line. If there is no such station (ic, if the collection of MetroStation is empty), your method should return null. • A method get PriorStop which takes as input a MetroStation and returns the stop prior to the MetroStation passed as input. You may assume that the MetroStation passed as input is indeed in the collection of MetroStations If the current station is the first stop on the MetroLine then this method should return null. You may assume that there are no "loops" in the MetroLine That is, no station is present on the same line twice. A method getNext Stop which takes as input a MetroStation and returns the stop after the MetroStation passed as input. You may assume that the Metrostation passed as input is indeed in the collection of Metrostations. If the current station is the last stop on the MetroLine, then this method should return null. You may assume that there are no "loops" in the MetroLine That is, no station is present on the same line twice. For the above methods, you may assume that there is no aliasing issue. That is to say, you can use == to compare the references, or if you are using a type such as ArrayList to maintain your list of stations, you can use the indexOf or contains method defined on an ArrayList.

For unlimited access to Homework Help, a Homework+ subscription is required.

Unlock all answers

Get 1 free homework help answer.
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in
Jean Keeling
Jean KeelingLv2
28 Sep 2018
Already have an account? Log in

Related questions

Related Documents

Weekly leaderboard

Start filling in the gaps now
Log in