/* +--------------------+ | Point |<---+ +--------------------+ | | String letterCoord | | | int numCoord | | +--------------------+ | | | +---------------------+ | | Road |<-------------+ +---------------------+ | | | String name | | | | Point endOne |----+ | | Point endTwo |----+ | | RoadList intersects |---------+ | +---------------------+ | | | | +----------+ | | | RoadList |<-------------+ | +----------+ | | +----------+ | | / \ | | --- | | | | | ------------------- | | | | | | +---------+ +---------------+ | | | NoRoad | | LargerRL | | | +---------+ +---------------+ | | +---------+ | Road first |--- | ---+ | RoadList rest |----+ +---------------+ */ class Point { String letterCoord; int numCoord; Point( String letterCoord, int numCoord ) { this.letterCoord = letterCoord; this.numCoord = numCoord; } } class Road { String name; Point endOne, endTwo; RoadList intersects; Road( String name, Point endOne, Point endTwo, RoadList intersects) { this.name = name; this.endOne = endOne; this.endTwo = endTwo; this.intersects = intersects; } //s55th.numReachable() == 0 //ellis.numReachable() == 3 //To calculate how many roads can be reached from this one int numReachable() { /// this.name ... this.endOne.PointMethod() ... this.endTwo.PointMethod() ... this.intersects.RoadListMethod() return this.intersects.count(); } } abstract class RoadList { abstract int count(); } class NoRoad extends RoadList { //To count how many Roads are in the NoRoad int count() { return 0; } } class LargerRL extends RoadList { Road first; RoadList rest; LargerRL( Road first, RoadList rest ) { this.first = first; this.rest = rest; } //ellis.intersects.count() == 3 //To count how many roads are in this LargerRL and all intersecting roads int count() { // ... this.first.RoadMethod() .. this.rest.RoadList() ... return 1 + this.first.numReachable() + this.rest.count(); } } /* Road hw66 = new Road( "hw66", new Point("A",1), new Point("E",1), new NoRoad()); Road s55th = new Road( "55th", new Point("A",1), new Point("E",1), new NoRoad()); Road s56th = new Road( "56th", new Point("A",2), new Point("E",2), new NoRoad()); Road s57th = new Road( "57th", new Point("A",3), new Point("E",3), new NoRoad()); Road ellis = new Road(" ellis", new Point("A",1), new Point("A",8), new LargerRL(s55th, new LargerRL(s56th, new LargerRL( s57th, new NoRoad())))); */ class Road2 { String name; Point endOne, endTwo; RoadList2 intersects; Road2( String name, Point endOne, Point endTwo) { this.name = name; this.endOne = endOne; this.endTwo = endTwo; this.intersects = new NoRoad2(); } //ellis2.addIntersection(s55th2) -> void // -> ((Larger)ellis2.intersects).first == s55th2 //Causes this road to intersect r //Note: modifies intersects for this void addIntersection( Road2 r ) { /// this.name ... this.endOne.PointMethod() ... this.endTwo.PointMethod() ... this.intersects.RoadListMethod() this.intersects = new LargerRL2( r, this.intersects ); } } abstract class RoadList2 { } class NoRoad2 extends RoadList2 { } class LargerRL2 extends RoadList2 { Road2 first; RoadList2 rest; LargerRL2( Road2 first, RoadList2 rest ) { this.first = first; this.rest = rest; } } class Map { RoadList2 roads; Map( RoadList2 roads ) { this.roads = roads; } //Create an intersection between two intersection roads //Note: modifies the intersects field of both r and r2 void createIntersection( Road2 r, Road2 r2 ) { r.addIntersection(r2); r2.addIntersection(r); } } /* Road2 s55th2 = new Road2( "55th", new Point("A",1), new Point("E",1)); Road2 ellis = new Road2("ellis", new Point("A",1), new Point("A",8)); new Map(new NoRoad2()).createIntersection( s55th2, ellis ) ellis s55th2 */