//////////////////////////////////////////////////////////////////////// // File routes-stations.java /* +-------------------------------------------------------+ | +-------------+ | v | v | +----------------------------+ | +-------------------------+ | | Route | | | Station | | +----------------------------+ | +-------------------------+ | | String name | | | String name | | | ALoS stations |-+ | | ALoR routes |-+ | +----------------------------+ | | +-------------------------+ | | | ALoS addStation(Station s) | | | | ALoS addRoute(Route r) | | | +----------------------------+ | | +-------------------------+ | | +---------------------+ | +---------------------+ | | | | | | +-------------+ | | +--------------+ | v v | | v v | | +------------------------+ | | +-------------------------+ | | | ALoS | | | | ALoR | | | +------------------------+ | | +-------------------------+ | | / \ | | / \ | | --- | | --- | | | | | | | | +------+------+ | | +------+---------+ | | | | | | | | | | v v | | v v | | +-------+ +-------------+ | | +-------+ +-----------+ | | | MTLoS | | ConsLoS | | | | MTLoR | | ConsLoR | | | +-------+ +-------------+ | | +-------+ +-----------+ | | | Station fst |-----+--+ | Route fst |---+--+ | ALoS rst |-----+ | ALoR rst |---+ +-------------+ +-----------+ */ class Route{ String name; ALoS stations; Route(String name){ this.name = name; this.stations = new MTLoS(); } // add a tation to the route, when initializing void addStation(Station s){ this.stations = new ConsLoS(s, this.stations); s.addRoute(this); } } abstract class ALoR { } class MTLoR extends ALoR{ MTLoR(){ } } class ConsLoR extends ALoR{ Route fst; ALoR rst; ConsLoR(Route fst, ALoR rst) { this.fst = fst; this.rst = rst; } } class Station { String name; ALoR routes; Station(String name){ this.name = name; this.routes = new MTLoR(); } // add a route to a station, when initializing void addRoute(Route r){ this.routes = new ConsLoR(r, this.routes); } } abstract class ALoS { } class MTLoS extends ALoS{ MTLoS(){ } } class ConsLoS extends ALoS{ Station fst; ALoS rst; ConsLoS(Station fst, ALoS rst) { this.fst = fst; this.rst = rst; } } // "Examples of stations" // Station ken = new Station("Kenmore"); // Station prk = new Station("Park"); // Station ctr = new Station("Center"); // Station nor = new Station("North"); // Station sci = new Station("Science"); // Station ash = new Station("Ashmont"); // Station dwn = new Station("Downtown"); // Station chs = new Station("Charles"); // "Make examples for the stations on the Blue Line: // Bowdoin, State, and Wonderland" // "Examples of routes" // Route green = new Route("Green"); // Route red = new Route("Red"); // "Add stations to the green line" // green.addStation(ken); // green.addStation(prk); // green.addStation(ctr); // green.addStation(nor); // green.addStation(sci); // green.addStation(ken); // "Add stations to the red line" // red.addStation(ash); // red.addStation(dwn); // red.addStation(prk); // red.addStation(chs);