Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My expected outcome with the below code should be: The route with the biggest time differential is 10013 EB 97 WB 106 with a time

My expected outcome with the below code should be:

The route with the biggest time differential is 10013 EB 97 WB 106 with a time difference of 9 minutes.

However, I am getting something completely different. I have added the table that is in the TravelDataPartial.csv file below as well. Please help figure out how to fix it so that I can get the above input!

COGID TravelDirection RouteID Route Card FromLocation ToLocation LengthInMiles FunctionalClass PostedSpeed FreeFlowSpeed AverageSpeed TTI FreeFlowTravelTime AverageTravelTime
10004 NB 45 N.M. 528 251 NORTH OF CORRALES RD. (NM 448) .118 MILES NORTH OF CORRAL 0.123 Urban Principal Arterial 50 50.1 48.8 1.03 9 9
10004 SB 45 N.M. 528 251 NORTH OF CORRALES RD. (NM 448) .118 MILES NORTH OF CORRAL 0.123 Urban Principal Arterial 50 52.5 49.7 1.06 8 9
10008 NB 45 N.M. 528 243 N.E. RIO VISTA S.W. OF RIO ARRIBA 0.474 Urban Principal Arterial 50 55 47.2 1.17 31 36
10008 SB 45 N.M. 528 243 N.E. RIO VISTA S.W. OF RIO ARRIBA 0.474 Urban Principal Arterial 50 55 47.1 1.17 31 36
10012 WB 321 NORTHERN BLVD. 11 EAST OF UNSER(NORTH) WEST OF IDALIA 0.757 Urban Minor Arterial 40 45 36.1 1.25 61 76
10012 EB 321 NORTHERN BLVD. 11 EAST OF UNSER(NORTH) WEST OF IDALIA 0.757 Urban Minor Arterial 40 40 37.2 1.08 68 73
10013 EB 321 NORTHERN BLVD. 40 EAST OF ROCKAWAY N.W. OF SARATOGA 1.038 Urban Minor Arterial 45 50 38.4 1.3 75 97
10013 WB 321 NORTHERN BLVD. 40 EAST OF ROCKAWAY N.W. OF SARATOGA 1.038 Urban Minor Arterial 45 50 35.2 1.42 75 106
10014 EB 321 NORTHERN BLVD. 24 EAST OF 40TH ST. WEST OF ROCKAWAY 0.348 Urban Minor Arterial 45 50 38.4 1.3 25 33
10014 WB 321 NORTHERN BLVD. 24 EAST OF 40TH ST. WEST OF ROCKAWAY 0.348 Urban Minor Arterial 45 50 35.2 1.42 25 36
10020 NB 45 N.M. 528 231 NORTH OF ROCKAWAY SOUTH OF NORTHERN 0.681 Urban Principal Arterial 45 45.1 40.6 1.12 54 61
10020 SB 45 N.M. 528 231 NORTH OF ROCKAWAY SOUTH OF NORTHERN 0.681 Urban Principal Arterial 45 50 35.8 1.41 49 69
10025 WB 321 NORTHERN BLVD. 15 EAST OF BROADMOOR WEST OF LOMA LARGA 1.029 Urban Minor Arterial 40 45 35.2 1.28 82 105
10025 EB 321 NORTHERN BLVD. 15 EAST OF BROADMOOR WEST OF LOMA LARGA 1.029 Urban Minor Arterial 40 41 38.3 1.07 90 97
10028 NB 45 N.M. 528 221 NORTH OF SUNDT SOUTH OF ROCKAWAY 0.237 Urban Principal Arterial 50 55 40.6 1.36 16 21
10028 SB 45 N.M. 528 221 NORTH OF SUNDT SOUTH OF ROCKAWAY 0.237 Urban Principal Arterial 50 55 35.8 1.55 16 24
10032 SB 45 N.M. 528 211 NORTH OF LEON GRANDE SOUTH OF SUNDT 0.514 Urban Principal Arterial 45 50 35.8 1.41 37 52
10032 NB 45 N.M. 528 211 NORTH OF LEON GRANDE SOUTH OF SUNDT 0.514 Urban Principal Arterial 45 45.1 40.6 1.12 41 46
10044 NB 45 N.M. 528 201 NORTH OF HIGH RESORT SOUTH OF LEON GRANDE 0.441 Urban Principal Arterial 45 45.1 40.6 1.12 35 39
10044 SB 45 N.M. 528 201 NORTH OF HIGH RESORT SOUTH OF LEON GRANDE 0.441 Urban Principal Arterial 45 50 35.8 1.41 32 45
10055 EB 321 NORTHERN BLVD. 12 EAST OF IDALIA WEST OF BROADMOOR 0.362 Urban Minor Arterial 40 40 37.2 1.08 33 35
10055 WB 321 NORTHERN BLVD. 12 EAST OF IDALIA WEST OF BROADMOOR 0.362 Urban Minor Arterial 40 45 36.2 1.25 29 36
10059 WB 416 SOUTHERN BLVD. 1 EAST OF IDALIA WEST OF RAINBOW 0.838 Urban Principal Arterial 35 43 40.8 1.06 70 74
10059 EB 416 SOUTHERN BLVD. 1 EAST OF IDALIA WEST OF RAINBOW 0.838 Urban Principal Arterial 35 44 43.4 1.01 69 69
10060 WB 416 SOUTHERN BLVD. 10 EAST OF ATLANTIC RD. WEST OF BALTIC 0.564 Urban Principal Arterial 35 43 40.8 1.06 47 50
10060 EB 416 SOUTHERN BLVD. 10 EAST OF ATLANTIC RD. WEST OF BALTIC 0.564 Urban Principal Arterial 35 44 43.4 1.01 46 47
10064 EB 416 SOUTHERN BLVD. 21 EAST OF BALTIC WEST OF PECOS LOOP 0.515 Urban Principal Arterial 40 45 35.7 1.26 41 52
10064 WB 416 SOUTHERN BLVD. 21 EAST OF BALTIC WEST OF PECOS LOOP 0.515 Urban Principal Arterial 40 45 36.6 1.23 41 51

public class TravelTimeData { private int COGID; private String firstDirection; private String secondDirection; private int firstTime; private int secondTime; private int timeDifference; public TravelTimeData(int COGID, String firstDirection, String secondDirection, int firstTime, int secondTime) { this.COGID = COGID; this.firstDirection = firstDirection; this.secondDirection = secondDirection; this.firstTime = firstTime; this.secondTime = secondTime; this.timeDifference = Math.abs(firstTime - secondTime); } public int getTimeDifference() { return timeDifference; } public String toString() { return COGID + " " + firstDirection + " " + firstTime + " " + secondDirection + " " + secondTime; } }

import java.util.Scanner; import java.io.File; import java.io.IOException; import java.util.ArrayList; //https://www.w3schools.com/java/java_arraylist.asp

public class Main {

public static void main(String[] args) { ArrayList travelData = new ArrayList<>(); try { File f = new File("TravelDataPartial.csv"); Scanner s = new Scanner(f); //Strip first line s.nextLine(); while(s.hasNext()) { //TODO: Lots of your code goes here //for file reading. String[] line = s.nextLine().split(","); int COGID = Integer.parseInt(line[0]); String firstDirection = line[1].trim(); String secondDirection = s.nextLine().split(",")[1].trim(); int firstTime = Integer.parseInt(line[2]); int secondTime = Integer.parseInt(s.nextLine().split(",")[2]); travelData.add(new TravelTimeData(COGID, firstDirection, secondDirection, firstTime, secondTime)); } s.close(); } catch(Exception e) { System.out.println("ERROR!"); e.printStackTrace(); } TravelTimeData largestDiff = getLargestDifferential(travelData); System.out.println("The route with the biggest differential is "); System.out.println(largestDiff); System.out.println(" with a time difference of " + largestDiff.getTimeDifference() + " minutes."); }

/* Take the data and return the route with the largest travel time differential. */ public static TravelTimeData getLargestDifferential(ArrayList data) { TravelTimeData largestDiff = data.get(0); for (int i = 1; i < data.size(); i++) { TravelTimeData curr = data.get(i); if (curr.getTimeDifference() > largestDiff.getTimeDifference()) { largestDiff = curr; } } return largestDiff; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions

Question

Enhance the basic quality of your voice.

Answered: 1 week ago

Question

Describe the features of and process used by a writing team.

Answered: 1 week ago