Fácil, tu función siempre tiene que retornar un valor booleano en su ejecución:
switch (operation) {
case DEPOSIT:
account.balance += sum;
return true;
case WITHDRAW:
if (account.balance < sum) {
System.out.println("Not enough money to withdraw.");
return false;
} else {
account.balance -= sum;
return true;
}
default:
return false;
}
tanto en el caso "Deposit" o "WITHDRAW" devuelve un boolean en caso que no sea ni "Deposit" , ni "WITHDRAW" devuelve false ahora si miras tu condiconal if te vas a dar cuenta que :
if (operation == Operation.DEPOSIT) {
account.balance += sum;
return true;
} else if (operation == Operation.WITHDRAW) {
if (account.balance < sum) {
System.out.println("Not enough money to withdraw.");
return false;
} else {
account.balance -= sum;
return true;
}
}
falta un caso para que tenga el mismo comportamiento que el , que es el caso ni DEPOSIT ni WITHDRAW :
if (operation == Operation.DEPOSIT) {
account.balance += sum;
return true;
} else if (operation == Operation.WITHDRAW) {
if (account.balance < sum) {
System.out.println("Not enough money to withdraw.");
return false;
} else {
account.balance -= sum;
return true;
}
}
solo debes agregar un return al final del metodo :
public static boolean changeBalance(Account account, Operation operation, Long sum) {
if (operation == Operation.DEPOSIT) {
account.balance += sum;
return true;
} else if (operation == Operation.WITHDRAW) {
if (account.balance < sum) {
System.out.println("Not enough money to withdraw.");
return false;
} else {
account.balance -= sum;
return true;
}
}
return false;
}