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 9 of 9

Thread: Need logic ....!!!

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need logic ....!!!

    Hi ,

    Requirement:-
    Ex: Today if some document comes to me , I need to iterate a string(document-id) with initial value of "000001" till the end of day. The 1st document will get "000001" as id and 2nd as "000002" and so on........till the end of day, if 10 documents had come...the final value of id must be "000010".

    When next day starts and again if document comes on that day, it is treated as 1st document for that day and its id must start with "000001". just like a repetition of above scenario.

    need logic for this requirement. Awaiting your response!

    Thanks!!!


  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: Need logic ....!!!

    Can you explain what your problem is?
    Counting from 1 shouldn't be a problem
    Is the problem detecting when a day starts so the program can reset the counter to 1?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need logic ....!!!

    yes, that is what exactly i am looking for..! can u share that particular piece of logic??

  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: Need logic ....!!!

    What part?
    to increment a counter:[code]
    counter++; // add 1 to counter[code]

    How do you want to detect a new day?
    One way would be to save the start day's value in a variable. When adding to the counter check it the current day is the same as the start day, if it is not, reset the counter and change start day's value to the current day.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    zach_l_b (March 30th, 2013)

  6. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need logic ....!!!

    ok!! will try now and let u know if i face any issues!!! Thanks for ur reply norm...!

    --- Update ---

    hi norm,

    I tried, but am not able to get...can u please share the template ??? I can't take the starts date value in a variable bcz every day morning, when document comes, it's created date will be "new Date()" .then id's will be 1,2,......till end of day. next day, if document comes ...its created date is also "new Date()" .....confused @ this part...!! plz help...!

  7. #6
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need logic ....!!!

    i cant save start day in variable. the requirement is like- if today, document comes ,its created date will be "new Date()" and id's should be 1,2,3......till end of day. next day, if document comes its created date is also"new Date()"........just confused here, plz help!! Thanks in advance

  8. #7
    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: Need logic ....!!!

    When the program is started, the start date variable is set to the current day.
    When a new doc comes in, check if the current date is the same as the start date that was saved when the program was started.
    If the current date is different from the start date, then set the counter to 1 and set the start date equal to the current date.

    When is the program stopped? How long does it execute for?
    Does the start date need to be saved in a file?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #8
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need logic ....!!!

    once that document details are stored in database along with its id, the program stops. no need of saving into file

  10. #9
    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: Need logic ....!!!

    Is the problem solved now with the use of a database?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Logic of Hangman
    By mhender24 in forum Loops & Control Statements
    Replies: 1
    Last Post: March 14th, 2013, 06:29 AM
  2. Not sure what the Logic Error is? [help]
    By Mitsuwa in forum Object Oriented Programming
    Replies: 2
    Last Post: January 27th, 2013, 11:55 PM
  3. Java Logic
    By JoshKesner in forum Java Theory & Questions
    Replies: 6
    Last Post: November 7th, 2012, 04:26 PM
  4. Name Logic for Program
    By aandcmedia in forum Java Theory & Questions
    Replies: 2
    Last Post: March 21st, 2012, 04:59 PM
  5. need logic
    By arunjib in forum Java Theory & Questions
    Replies: 3
    Last Post: November 27th, 2011, 05:39 PM