• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Calculate total from list of lists and map to pojo

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I need to process my array list and calculate the total that is take from each account balance.
I can't have another data structure as per homework.



POJO's



First though was to loop over the list and



This does not work as the previous total is added to the next customer.

A potential solution would be to add an accountKey to the Customer and Account, so I can have a constant in both lists, to check if they match and calculate the total.
Maybe that would stop the addition of balance to the next customer.
I don't think that is a go, tho.

Thank you for reading.
 
Saloon Keeper
Posts: 11122
88
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does it mean for an Account to have a total? Doesn't the balance represent the total? It seems like what you are looking for is a Customer total which is a total of all of the balances in all the accounts that the  customer has.
 
Craig Star
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you, I understand now where I was wrong.
A customer is one and accounts are many.
Still, if I would have wanted to have a variable in each account, as "totalForAllAcounts", how would that be achievable?

customer: details
Account: details of the account + new field totalOfAllAccounts



I can solve the sew field in the customer.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would each Account have a total for all accounts?
That doesn't make much sense.
 
Craig Star
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After some thought I understand.
If in any case there should be such a requirement, it would point a reference to the total in the Customer pojo
reply
    Bookmark Topic Watch Topic
  • New Topic