Results 1 to 14 of 14
  1. #1
    skybeorn is offline Member
    Join Date
    Mar 2012
    Posts
    18
    Rep Power
    0

    Default Trying to create a running total.

    I have been writing an application for a Point of Sale system. It's based on a grocery store idea. So far, i have been doing pretty well, but i have not been able to figure out this last problem.

    When i print My Invoice i also want to show a running total of sales for that day.

    I have already been able to get the total for one transaction, but i can't seem to think about how i would create the total for several transactions and show it on each receipt.

    Any Help would be great!
    You can find my Source Code here.
    https://github.com/Skybeorn/Discount...ountstrategyme

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: Trying to create a running total.

    how i would create the total for several transactions and show it on each receipt.
    Can you show what the program currently prints out and explain how you want to change it

    If you have questions about your code, please post it here on the forum.

  3. #3
    skybeorn is offline Member
    Join Date
    Mar 2012
    Posts
    18
    Rep Power
    0

    Default Re: Trying to create a running total.

    Output as is...
    101
    Jane Doe

    ID Name Qty Cost Discount Total
    ================================================== ===============
    1 Milk 8.0 15.0 30.0 90.0
    2 Juice 10.0 10.0 50.0 50.0
    3 Tea 25.0 5.0 0.0 125.0

    ==================================
    Total Owned: 265.0
    Total Saved: 80.0



    Trying to get it like this.
    102
    John Doe

    ID Name Qty Cost Discount Total
    ================================================== ===============
    1 Milk 8.0 15.0 30.0 90.0
    2 Juice 10.0 10.0 50.0 50.0
    3 Tea 25.0 5.0 0.0 125.0

    ==================================
    Total Owned: 265.0
    Total Saved: 80.0
    ==================================
    Total Saved for day: 160.0
    Total Sales: 530.0

    Does that make sense? I having trouble thinking of how to store the Total Sales and Discounts.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default Re: Trying to create a running total.

    If this is a simple standalone program, then a simple static hashmap, if it is a web/enterprise application, then an attributes in the application context or a persistent bean.

    Edit: And, of course, you always have the option of using files or a db to store the "running" totals.

  5. #5
    skybeorn is offline Member
    Join Date
    Mar 2012
    Posts
    18
    Rep Power
    0

    Default Re: Trying to create a running total.

    Never done a hash map before...

    Or file writing, or used a DB. I know that sounds funny. Need i post my code?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: Trying to create a running total.

    I don't thick you need any of those if the program has all the data it needs to generate the report. You would only need those things if you wanted to save the data for more than one execution of the program. Say from one day to rhe next.

  7. #7
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default Re: Trying to create a running total.

    He Seems, from the Sample Output, to at least Need it from Order to Order. So, no, judging by that it is Not all in the Same "Session".

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: Trying to create a running total.

    The OP will have to determine how his code is to work depending on ...

  9. #9
    skybeorn is offline Member
    Join Date
    Mar 2012
    Posts
    18
    Rep Power
    0

    Default Re: Trying to create a running total.

    One Customer comes in and buys whatever items they need.

    The application finds the items in a DB(Since i don't have a DB i'm using an array with just a couple items), looks to see if they have a Discount strategy and then applies that discount.

    Then the app totals the sale amount up, and the discount and prints it out to the console, showing the output you see from Jane Doe.
    That is one session.

    The next session:
    Then John Doe comes in and buys whatever he needs. The app does the same thing again.

    What i am trying to do is take Jane's and John's Total discount and total bill, add them together and show the Running Total in Sales and Discount for that store.

  10. #10
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default Re: Trying to create a running total.

    Then a Single Set of additional variables is all you need.

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: Trying to create a running total.

    What do you mean by a session? Is that a different execution of the program, maybe on different days?

  12. #12
    skybeorn is offline Member
    Join Date
    Mar 2012
    Posts
    18
    Rep Power
    0

    Default Re: Trying to create a running total.

    When I said Session, I just mean one transaction, or one customer buying something.

  13. #13
    skybeorn is offline Member
    Join Date
    Mar 2012
    Posts
    18
    Rep Power
    0

    Default Re: Trying to create a running total.

    Quote Originally Posted by masijade View Post
    Then a Single Set of additional variables is all you need.
    Ok, I guess i'm a little lost as where i need to put them in my app. I'm pretty sure it needs to be in my invoice Class. I am going to try some things. I really appreciate your comments and help

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: Trying to create a running total.

    You could save the running totals in class variables.

Similar Threads

  1. Create Table to Add Total
    By savio21 in forum New To Java
    Replies: 2
    Last Post: 11-30-2011, 03:58 PM
  2. Keeping track of running total help
    By masterasia in forum JCreator
    Replies: 1
    Last Post: 03-25-2011, 07:26 AM
  3. Running total little help
    By silverspoon34 in forum Forum Lobby
    Replies: 9
    Last Post: 02-27-2011, 09:19 PM
  4. Replies: 12
    Last Post: 08-26-2010, 10:14 AM
  5. Running Total by Key Group in HashMap
    By KevMull in forum New To Java
    Replies: 3
    Last Post: 11-16-2009, 03:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •