// RoadNetwork.java /** Road network simulator (or it will become one once it's done) * @author Douglas W. Jones * @version Feb. 12, 2021 */ import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.Collection; class Road { Intersection source; // road from here Intersection destination; // road to there double travelTime; // time in seconds public Road( Scanner in ) { // BUG: need detail! } // BUG: need to add behavior for roads } class Intersection { // BUG: is collection the right class? Should I pick a subclass? Collection incoming; // the roads leading here Collection outgoing; // the roads that come from here public Intersection( Scanner in ) { // BUG: need detail! } // BUG: need to add behavior for roads } public class RoadNetwork { /** build a road network model by scanning an input file * @param in -- the scanner used to read the file * Input file contains keywords road and intersection, * details beyond that are handled by the appropriate classes */ private static void buildModel( Scanner in ) { while (in.hasNext()) { String keyword = in.next(); if ("intersection".equals( keyword )) { new Intersection( in ); } else if ("road".equals( keyword )) { new Road( in ); } else { System.err.println( "not a keyword in the input: " + keyword ); } } } /** main method mostly concerned with command line arguments * @param args -- the command line arguments * Want just one argument, the file name for model description */ public static void main( String[] args ) { // arg[0] should be the name of a file describing a road network if (args.length < 1) { System.err.println( "missing command line argument, a file name" ); } else if (args.length > 1) { System.err.println( "extra command line argument: " + args[1] ); } else { try { buildModel( new Scanner( new File( args[0] ) ) ); // BUG: simulate the network that was built } catch ( FileNotFoundException e ) { System.err.println( "could not open file: " + args[0] ); } } } }