Changed the element of a LinkedList - Need to change the rest

user3516525

My program is a train schedule showing cities and arrival and departure times. In the program you can type "Delay" and then type the city name and #ofminutes to add a delay in minutes to that cities arrival time. This information is all stored in a LinkedList

Station        Arrival        Departure      Day            
Vancouver      -----          20:30          1              
Kamloops       06:00          06:35          2              
Jasper         16:00          17:30          2              
Edmonton       23:00          23:59          2              
Saskatoon      08:00          08:25          3              
Winnipeg       20:45          22:30          3 

My output starts off like this ^^^

So in my 'delay' method I am able to bring up the city specified and add the minutes to the arrival time and everything works great. Code for this is below:

public void delay(String station,int minute){
    String cityDelay=station;
    int timeDelay=minute;
    for(Station list: schedule){
        if (cityDelay.equalsIgnoreCase(list.getCity())){                    
            Calendar c = list.getArrivalDate();                 
            c.add(Calendar.MINUTE, timeDelay);              
            System.out.println(list.getArrival());  //to see if it updated             
        }           
    }               
}

However, it is this point where I have to add those same minutes to the rest of the times on the list but not have it apply those changes to cities before the delay was implemented.

For example, if I type in "Edmonton" and "30", the output should look like this:

Station        Arrival        Departure      Day            
Vancouver      -----          20:30          1              
Kamloops       06:00          06:35          2              
Jasper         16:00          17:30          2              
Edmonton       23:30          00:29          2              
Saskatoon      08:30          08:55          3              
Winnipeg       21:15          23:00          3 

(I will figure out how to update the day after I get times working)

I have no idea how to loop through this and apply the update of minutes to the remainder of the list while excluding the elements prior to the selected city. Any looping ideas I can think of would just go through the entire list. Thoughts? Concepts I should look up/google? Thanks in advance.

Chetan Jadhav CD

You can use the following modified code to update the arrival times of the cities/stations coming after the city/station for which the delay was added:

public void delay(String station,int minute){
String cityDelay=station;
int timeDelay=minute;
boolean updateRest = false;
for(Station list: schedule){
    if (cityDelay.equalsIgnoreCase(list.getCity())){                    
        updateRest = true;          
    }
    if(updateRest){
        Calendar c = list.getArrivalDate();                 
        c.add(Calendar.MINUTE, timeDelay);              
        System.out.println("City: "+list.getCity()+"Updated Arrival time: "+ list.getArrival());  //to see if it updated   
    }
}
updateRest = false;
}

You can also insert the logic to update the day in the if(updateRest) block if you want to change that too. Hope this helps.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

change element position in linkedList

From Dev

change element position in linkedList

From Dev

AngularJS: ng-change called before an select element is changed

From Dev

AngularJS: ng-change called before an select element is changed

From Dev

Finding element in LinkedList with lambda

From Dev

Search for an element in a LinkedList

From Dev

Why do you need (LinkedList)?

From Dev

Need to search object elements in a LinkedList

From Dev

How head.next is changed in singly linkedlist

From Dev

How head.next is changed in singly linkedlist

From Dev

Need to change this JQuery code to check for element existence prior to processing

From Dev

I changed my Firebase rules to all authenticated users.. What I need to change in requests (Flutter)

From Dev

I need to execute a thread at intervals that can change and is being dynamically changed by another thread

From Dev

In need of a script to detect when a cell's numeric value has changed, and change the row colour

From Dev

How to get previous element in a LinkedList?

From Dev

Removing the first element in a circular linkedList

From Dev

Removal of an element from LinkedList at index

From Dev

How can I change data-value in bootstrap editable element after it's changed?

From Dev

Array is treated as constant pointer,so we cannot change the pointer value but individually element of an array can be changed why?

From Dev

How to efficiently remove an element from java LinkedList

From Dev

Java - Removing an element from LinkedList except first

From Dev

Java checking last element of LinkedList that is part of a TreeMap

From Dev

Delete specific element from LinkedList....?

From Dev

Java foreach method from second element in LinkedList

From Dev

Insert new element as the head of the Linkedlist Python

From Dev

Get element being changed in contenteditable

From Dev

Return dictionary with one changed element

From Dev

Click a button on dynamically changed element

From Dev

Get element being changed in contenteditable

Related Related

  1. 1

    change element position in linkedList

  2. 2

    change element position in linkedList

  3. 3

    AngularJS: ng-change called before an select element is changed

  4. 4

    AngularJS: ng-change called before an select element is changed

  5. 5

    Finding element in LinkedList with lambda

  6. 6

    Search for an element in a LinkedList

  7. 7

    Why do you need (LinkedList)?

  8. 8

    Need to search object elements in a LinkedList

  9. 9

    How head.next is changed in singly linkedlist

  10. 10

    How head.next is changed in singly linkedlist

  11. 11

    Need to change this JQuery code to check for element existence prior to processing

  12. 12

    I changed my Firebase rules to all authenticated users.. What I need to change in requests (Flutter)

  13. 13

    I need to execute a thread at intervals that can change and is being dynamically changed by another thread

  14. 14

    In need of a script to detect when a cell's numeric value has changed, and change the row colour

  15. 15

    How to get previous element in a LinkedList?

  16. 16

    Removing the first element in a circular linkedList

  17. 17

    Removal of an element from LinkedList at index

  18. 18

    How can I change data-value in bootstrap editable element after it's changed?

  19. 19

    Array is treated as constant pointer,so we cannot change the pointer value but individually element of an array can be changed why?

  20. 20

    How to efficiently remove an element from java LinkedList

  21. 21

    Java - Removing an element from LinkedList except first

  22. 22

    Java checking last element of LinkedList that is part of a TreeMap

  23. 23

    Delete specific element from LinkedList....?

  24. 24

    Java foreach method from second element in LinkedList

  25. 25

    Insert new element as the head of the Linkedlist Python

  26. 26

    Get element being changed in contenteditable

  27. 27

    Return dictionary with one changed element

  28. 28

    Click a button on dynamically changed element

  29. 29

    Get element being changed in contenteditable

HotTag

Archive