A
aver24
I realize that this program is for beginners. In any case, I can't find
the problem. Here it is:
(It's supposed to print out alice: balance = 625; bob = 436; I don't
think it's adding the interest and I can't see why)
public class BankDemo {
public static void main(String[] args) {
BankAccount alice = new BankAccount(0);
BankAccount bob = new BankAccount(0);
alice.deposit(500);
bob.deposit(500);
System.out.println("Alice's balance: " + alice.getBalance());
System.out.println("Bob's balance: " + bob.getBalance());
alice.addInterest(5);
alice.transferFunds(bob, 100);
bob.addInterest(6);
bob.transferFunds(alice, 200);
System.out.println("Alice's balance: " + alice.getBalance());
System.out.println("Bob's balance: " + bob.getBalance());
System.out.println("Alice:\t" + alice);
System.out.println("Bob:\t" + bob);
}
}
class BankAccount {
public BankAccount(double initialBalance) {
double balance = initialBalance;
}
public void deposit(double amount) {
balance = balance + amount;
}
public void withdraw() {
balance = balance - 100;
}
public void withdraw(double amount) {
balance = balance - amount;
}
public double getBalance() {
return balance;
}
public String toString() {
return "BankAccount [balance=" + balance + "]";
}
private double balance = 0;
public void addInterest(double interestRate) {
double Interest = interestRate / 100;
}
public void setBalance(double amount) {
withdraw(getBalance());
deposit(amount);
}
public void transferFunds(BankAccount name, double amount) {
withdraw(amount);
name.deposit(amount);
}
}
// add 5% interest to alice's account balance
//alice.addInterest(5);
// move $100 from alice's account into bob's
// alice.transferFunds(bob, 100);
// add 6% interest to bob's account balance
//bob.addInterest(6);
// move $200 from bob's account into alice's
//bob.transferFunds(alice, 200);
//System.out.println("Alice:\t" + alice);
//System.out.println("Bob:\t" + bob);
the problem. Here it is:
(It's supposed to print out alice: balance = 625; bob = 436; I don't
think it's adding the interest and I can't see why)
public class BankDemo {
public static void main(String[] args) {
BankAccount alice = new BankAccount(0);
BankAccount bob = new BankAccount(0);
alice.deposit(500);
bob.deposit(500);
System.out.println("Alice's balance: " + alice.getBalance());
System.out.println("Bob's balance: " + bob.getBalance());
alice.addInterest(5);
alice.transferFunds(bob, 100);
bob.addInterest(6);
bob.transferFunds(alice, 200);
System.out.println("Alice's balance: " + alice.getBalance());
System.out.println("Bob's balance: " + bob.getBalance());
System.out.println("Alice:\t" + alice);
System.out.println("Bob:\t" + bob);
}
}
class BankAccount {
public BankAccount(double initialBalance) {
double balance = initialBalance;
}
public void deposit(double amount) {
balance = balance + amount;
}
public void withdraw() {
balance = balance - 100;
}
public void withdraw(double amount) {
balance = balance - amount;
}
public double getBalance() {
return balance;
}
public String toString() {
return "BankAccount [balance=" + balance + "]";
}
private double balance = 0;
public void addInterest(double interestRate) {
double Interest = interestRate / 100;
}
public void setBalance(double amount) {
withdraw(getBalance());
deposit(amount);
}
public void transferFunds(BankAccount name, double amount) {
withdraw(amount);
name.deposit(amount);
}
}
// add 5% interest to alice's account balance
//alice.addInterest(5);
// move $100 from alice's account into bob's
// alice.transferFunds(bob, 100);
// add 6% interest to bob's account balance
//bob.addInterest(6);
// move $200 from bob's account into alice's
//bob.transferFunds(alice, 200);
//System.out.println("Alice:\t" + alice);
//System.out.println("Bob:\t" + bob);