A
aver24
I'm new to programming. When I compile this program, I get this error
message:
line 3: BankAccount(int) in BankAccount cannot be applied to ()
same error in Line 4. This one has me stumped. Can someone see
something I'm missing?
public class BankDemo {
public static void main(String[] args) {
BankAccount alice = new BankAccount(),
bob = new BankAccount();
alice.deposit(500);
bob.deposit(200);
alice.withdraw(100);
bob.deposit(300);
System.out.println("Alice's balance: " + alice.getBalance());
System.out.println("Bob's balance: " + bob.getBalance());
}
}
class BankAccount {
public BankAccount(int initialBalance) {
balance = initialBalance;
}
public void deposit(int amount) {
balance = balance + amount;
}
public void withdraw() {
balance = balance - 100;
}
public void withdraw(int amount) {
balance = balance - amount;
}
public int getBalance() {
return balance;
}
public String toString() {
return "BankAccount [balance=" + balance + "]";
}
private int balance = 0;
}
message:
line 3: BankAccount(int) in BankAccount cannot be applied to ()
same error in Line 4. This one has me stumped. Can someone see
something I'm missing?
public class BankDemo {
public static void main(String[] args) {
BankAccount alice = new BankAccount(),
bob = new BankAccount();
alice.deposit(500);
bob.deposit(200);
alice.withdraw(100);
bob.deposit(300);
System.out.println("Alice's balance: " + alice.getBalance());
System.out.println("Bob's balance: " + bob.getBalance());
}
}
class BankAccount {
public BankAccount(int initialBalance) {
balance = initialBalance;
}
public void deposit(int amount) {
balance = balance + amount;
}
public void withdraw() {
balance = balance - 100;
}
public void withdraw(int amount) {
balance = balance - amount;
}
public int getBalance() {
return balance;
}
public String toString() {
return "BankAccount [balance=" + balance + "]";
}
private int balance = 0;
}