Hi Guys,
How can I workout the sum of money from an array:
accs[0] = new Account( "Name here2", 121, 510 ) ;
accs[1] = new Account( "Name here", 12, 50 ) ;
I want to add the last 2 numbers for both items together to workout the total.
Printable View
Hi Guys,
How can I workout the sum of money from an array:
accs[0] = new Account( "Name here2", 121, 510 ) ;
accs[1] = new Account( "Name here", 12, 50 ) ;
I want to add the last 2 numbers for both items together to workout the total.
Since the array is made up of Account objects, you will need to access the data through methods in that class. Something like getBalance, getTotal..... After you have that method, it's pretty straightforward.
Code://assuming that the getBalance method returns an int
int total = accs[0].getBalance() + accs[1].getBalance();