Hi guyz,
I''ve done a bank's savings account program in java but can't compile, I keep on gettin the errors.
1. overrides java.lang.Object.toString
2. This methode must return a result of type String.
both of the errors are on the method public String toString () {...
public class SavingsAccount {
private String password,branch,sur,first,account;
private int amount;
private double balance = 0;
public void initialiseAccount (String accountNumber, String initPassword, String branchName, String surname, String firstNames) {
account = accountNumber;
password = initPassword;
branch = branchName;
first = firstNames;
sur = surname;
}
public String toString() {
System.out.println ("Account Number: "+account);
System.out.println ("Branch: "+branch);
System.out.println ("Name: "+first+" "+sur);
}
public boolean withdrawCash (int amount) {
boolean result = false;
if (amount > balance)
System.out.println("Insufficient funds");
else {
balance -= amount;
System.out.println("Withdrawal successful");
result = true;
}
return result;
}
public void depositCash (int amount) {
balance += amount;
System.out.println("Deposit successful");
}
public void changeUserPassword (String oldPassword, String newPassword) {
if (oldPassword.equals(password))
System.out.println("Password change successful");
else
System.out.println("Old password does not match");
}
public double printBalance () {
if (balance == 0)
System.out.printf("Balance: R"+"%.2f",balance);
else {
System.out.printf("Balance: R"+"%.2f",balance);
}
System.out.println();
return balance;
}
}