This is a Java program consisting of two classes. The basic idea is a bank account. I am having trouble calling a method called 'mystery' from the Account to the Tester. Program being used is BlueJ, if that helps to explain the code layout.
Account:
Tester:public class BankAccount { private double balance; public BankAccount() { balance = 0; } public BankAccount(double initialBalance) { balance = initialBalance; } public void deposit(double amount) { double newBalance = balance + amount; balance = newBalance; } public void withdraw(double amount) { double newBalance = balance - amount; balance = newBalance; } public double getBalance() { return balance; } public void mystery(BankAccount that, double amount) { this.balance = this.balance - amount; that.balance = that.balance + amount; } }
public class BankAccountTester { public static void main(String[] args) { //Initial balance BankAccount bankAcct = new BankAccount(10000); System.out.println("Balance should be equal to: 10000"); System.out.println("Initial Balance: " + bankAcct.getBalance()); //Withdraw 200 bankAcct.withdraw(2000); System.out.println("Balance should be equal to: 8000"); System.out.println("Actual balance: " + bankAcct.getBalance()); //Deposit 100 bankAcct.deposit(100); System.out.println("Balance should be equal to: 8100"); System.out.println("Actual balance: " + bankAcct.getBalance()); //Withdraw 1000 bankAcct.withdraw(1000); System.out.println("Balance should be equal to: 7100"); System.out.println("Actual balance: " + bankAcct.getBalance()); //'mystery' method result System.out.println("Mystery Method result: "); } }
Thanks in advance for any help. I'm a Web Design major that somehow ended up in a programming class, so it's a bit over my head and I just need a little guidance now and then.