import java. io. File; import java. util. LinkedList; import java. util. Scanner
ID: 3871149 • Letter: I
Question
import java. io. File; import java. util. LinkedList; import java. util. Scanner; Roads are one-way streets linking intersections ee Intersection class Road //measured in seconds float travelTime; Intersection destination; //where the road goes Intersection source; //name of road is source-destination //where the comes from Intersections join roads see Road class Intersection String name; LinkedList Road» outgoing LinkedList Road» incoming new LinkedList Road» () ; new LinkedList Road () ; Bug: multiple types of intersections (uncontrolled, stoplight) RoadNetwork, the main class to build a network of roads and intersections see Road ee Intersection k/ public class RoadNetwork public static void main (String[] args) [ //Bug: Must add code to see if there is a file name Scanner scnew Scanner ( new File( args[0]) // Bug: What if the file doesn' t exist?Explanation / Answer
Now that you just have one intersection, you will preferably delete the Intersection class.
The Road class will now not have Intersection objects. Now that there is only 1 intersection, there can only be two possibilities for each road : it can be either incoming to the intersection or it can be outgoing from the intersection.
So we can rather have only one integer variable that signifies whether the road is an incoming one with respect to the intersection or is it outgoing.
in_or_out = 1 if incoming
in_or_out = -1 if outgoing
So the definition of the class road is reduced to the following:
class Road {
float travelTime;
int in_or_out;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.