6. Errors, Organization, and Scaffolding
Part of
CS:2820 Object Oriented Software Development Notes, Fall 2020
|
In the description of the data structures, we already decided that travel times are given in seconds. For long roads, it would be useful to give times in other time units such as minutes or hours. For now, we'll assume that times are given in seconds, with the full knowledge that this is an indadequate design.
Here is class Road with a preliminary version of a reasonable initializer to read from the above file:
/** Roads are one-way streets linking intersections * @see Intersection */ class Road { float travelTime; //measured in seconds Intersection destination; //where the road goes Intersection source; //where the comes from // name of road is source-destination // initializer public Road( Scanner sc, LinkedList <Intersection> inters ) { // code here must scan & process the road definition string sourceName = sc.next(); string dstName = sc.next(); // Bug: Must look up sourceName to find source // Bug: Must look up dstName to find destination // Bug: What if the next isn't a float travelTime = sc.nextFloat(); string skip = sc.nextLine(); } }
There are, of course, some bugs here! We need to do quite a bit of work, and, of course, we need to write the corresponding code for class Intersection.