Hi guys, i have been able to get this transfer function to work but only with one account. i'm not too sure how to get it working for the other account also. Any help would be greatly appreciated.

static String doTransfer(String amount){ 
    // Withdraw cash -- called from ATMWithdrawl
    String newBalance = "";
    String newBalance1 = "";
    // Turn Strings to doubles for arithmatic
    double transferAmount=                 
        (new Double(amount)).doubleValue();
    double currentBalance= 
        (new Double(account_inf[0][4])).doubleValue(); 
    double currentBalance1= 
        (new Double(account_inf[1][4])).doubleValue(); 
    // Get the new balance as a string & update the account_inf array    
    if (transferAmount <= currentBalance) {
    newBalance = Double.toString
                    (currentBalance - transferAmount);
      account_inf[0][4] = newBalance;
      newBalance1 = Double.toString
                    (currentBalance + transferAmount);
      account_inf[1][4] = newBalance1;
    }
      else if (transferAmount <= currentBalance1) {
    newBalance1 = Double.toString
                    (currentBalance1 - transferAmount);
      account_inf[1][4] = newBalance;
    newBalance = Double.toString
                    (currentBalance1 + transferAmount);
      account_inf[0][4] = newBalance1;
    
    } 
    return newBalance;

}

I'm putting the problem down to not being able to use more than 1 return statement?

Recommended Answers

All 2 Replies

Looks to me like "account_inf" holds the information of all of your accounts, so in order to make it work you should add two more parameters to that method to tell it which accounts to access from the array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.