# Please help with Java homework!



## WillEat4F00d (Jan 20, 2012)

I posted this over at xda already but no one is answering me and I'm desperate for an answer because it's due soon lol.









Okay here's the thing:

I have an assignment in Java class that's due in 1.5 hours and figured that this would be the best place to ask since you guys are (hopefully) good at this kind of stuff. 

Here's the code:

/**
* Exercise 3.
*
* Complete the setBalances method below to set all accounts in an array to the specified value.
*
* The test methods should pass.
*
*/
public class AccountMethods {

public static void main(String[] args) {
Account[] accounts = {new Account(100, "joe"),
new Account(200, "jane"),
new Account(300, "jerry")};
testSetBalances(accounts, 50);
testBalanceNonNegative();
}

*public static void setBalances(Account[] accounts, double value) {
double balance = 0;
for (int i = 0; i < accounts.length; i++) {
balance += accounts.getBalance();*_
}
}

public static boolean testSetBalances(Account[] accounts, double value) {
setBalances(accounts, value);
for (int i = 0; i < accounts.length; i++) {
if (accounts.getBalance() != value) {
System.out.println("testSetBalances fails on element " + i);
return false;
}
}
System.out.println("testSetBalances passes.");
return true;
}

public static boolean testBalanceNonNegative() {
Account a = new Account(100, "jim");
a.setBalance(-100);
if (a.getBalance() < 0) {
System.out.println("testBalanceNonNegtaive fails");
return false;
} else {
System.out.println("testBalanceNonNegative passes.");
return true;
}
}

}

The bold part is what I'm suppose to be working with, but I can't get it to pass in the testSetBalances method. I don't know if I'm explaining this right, but when I'm compiling the code, it's suppose to say:

testSetBalances passes

But instead, it's saying: testSetBalances fails on element 0

Don't worry about the other parts of the code because the assignment for that is done already._


----------



## Dark Jedi (Nov 3, 2011)

Maybe no one is answering because if someone else does the work for you. Then you learn nothing.

Sent from my ADR6400L using Tapatalk


----------



## kvswim (Aug 20, 2011)

My teacher will walk us through it if you admit defeat.

Sent from my SCH-I510 using RootzWiki


----------

