Within a particular class (Assets), I have a series of related variables like so:
private long checkingBalance;
private long savingsBalance;
private long moneyMarketBalance;
...the list goes on.
Logically, I know they're all related, so I want to add up all of these variables and display the sum. What I don't want to do is manually type out
total = checkingBalance + savingsBalance + moneyMarketBalance + indexFundBalance + mutualFundBalance + whatever
and so forth. I feel like there must be a better way of doing this.
So, is there? I'm thinking there's got to be a way to define some sort of arbitrary set or collection and just tell Java to loop through it and add up all its members. Should I create another class called Balances or something with all those variables as attributes? Otherwise I considered using an array but that seems hackish.
Thanks!