Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: How to check time in LinkedList?

  1. #1
    Junior Member
    Join Date
    Apr 2020
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to check time in LinkedList?

    I want to check a correctness of time when I have hours and minutes in my LinkedList. I am adding new elements to LinkedList like below. In System.out.println(mylist); It should be 3:30. A verification can be before adding to the LinkedList as well.
    LinkedList<Trs> mylist = new LinkedList<Trs>();
     
        mylist.add(new Trs(2,90));
    Last edited by hulkjava; April 25th, 2020 at 06:05 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to check time in LinkedList?

    Can you post the program's output that shows what you are talking about?

    Also post the code. Be sure to wrap the code in code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2020
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to check time in LinkedList?

    My code is too long so I put a piece of code only.
    2 is int and 90 is int.
    Last edited by hulkjava; April 25th, 2020 at 06:13 AM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to check time in LinkedList?

    2 is int ant 90 is int.
    Ok those are two int values.
    Can you explain what the problem is?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2020
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to check time in LinkedList?

    It is for example 2:90 on the clock. It should be automatically 3:30. I can add to my LinkedList 2:90. Should I check a correctness ot the time before adding to LinkedList or after? for example converting 2:90 to 3:30 o clock.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to check time in LinkedList?

    One way would be for the Trs class to throw an exception when it was given bad data.

    What is the definition of the correct values that can be passed to the Trs constructor?
    What should the Trs constructor do with the values it receives? For example you suggest that H=2, M=90 should be converted to H=3, M=30
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2020
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to check time in LinkedList?

    Quote Originally Posted by Norm View Post
    One way would be for the Trs class to throw an exception when it was given bad data.

    What is the definition of the correct values that can be passed to the Trs constructor?
    What should the Trs constructor do with the values it receives? For example you suggest that H=2, M=90 should be converted to H=3, M=30

    My Trs constructor define only (int hour, int minute) nothing more.
    If my constructor receive for 2, 90 it should convert to h=3 and m=30 I think it is good way.
    I thought that I add to my LinkedList data like h=2 and m=90 and later when I want to print this to the console I convert this to h=3, m=30.
    I am not sure what way is better to resolve this.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to check time in LinkedList?

    I think the Trs constructor should test and convert its parameters to valid values, unless it is needed to save the original input for some reason.

    I don't see why the linkedlist should see the contents of the objects (Trs) that it contains. The Trs class should provide any needed access to its contents.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Converting Military Time to Standard Time
    By GMPoison in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 30th, 2014, 01:28 AM
  2. Using Date() to get Start Time and Finish Time of a copyFiles method
    By dalythe in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: June 17th, 2013, 09:50 PM
  3. Hello, first time caller long time programmer....
    By P2C2N in forum Member Introductions
    Replies: 3
    Last Post: December 10th, 2012, 11:53 AM
  4. addInOrder LinkedList
    By PeskyToaster in forum Collections and Generics
    Replies: 1
    Last Post: April 6th, 2012, 06:16 AM
  5. LinkedList of String
    By oxnume in forum Collections and Generics
    Replies: 3
    Last Post: April 6th, 2012, 12:12 AM

Tags for this Thread