Strange error message

Discussion in 'Java' started by aver24@hotmail.com, Nov 26, 2005.

  1. Guest

    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;
    }
    , Nov 26, 2005
    #1
    1. Advertising

  2. Rhino Guest

    <> wrote in message
    news:...
    > 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?
    >

    Generally we'd have a lot better chance of helping if you gave the exact
    error message, not a paraphrase. However, in this case, the problem seems to
    be lines three and four are written with a comma between them. Change lines
    three and four as follows and see what happens:

    BankAccount alice = new BankAccount();
    BankAccount bob = new BankAccount();

    I think this will solve your problem.

    Rhino

    >
    > 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;
    > }
    >
    Rhino, Nov 26, 2005
    #2
    1. Advertising

  3. Lee Weiner Guest

    In article <>, wrote:
    >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();
    >}
    >class BankAccount {
    > public BankAccount(int initialBalance) {
    > balance = initialBalance;
    > }
    >}
    >


    The only constructor in class BankAccount requires that an int be passed as a
    parameter to initialize the account to a balance. Your code in main() is
    trying to construct two BankAccount objects without passing in the int
    parameter:
    BankAccount alice = new BankAccount( 1000 );

    Lee Weiner
    lee AT leeweiner DOT org
    Lee Weiner, Nov 26, 2005
    #3
  4. Roedy Green Guest

    On 25 Nov 2005 20:18:26 -0800, wrote, quoted or
    indirectly quoted someone who said :

    use:
    > BankAccount alice = new BankAccount(),


    declaration:
    > public BankAccount(int initialBalance) {


    Don't you see the mismatch?
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Nov 26, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Wehofer

    Strange error message at client

    Robert Wehofer, Nov 17, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    443
    Chris Jackson
    Nov 17, 2003
  2. jack
    Replies:
    0
    Views:
    710
  3. Replies:
    0
    Views:
    328
  4. David
    Replies:
    2
    Views:
    467
    Thomas Kellerer
    Aug 13, 2006
  5. Rogério Brito
    Replies:
    1
    Views:
    660
    Sean DiZazzo
    Sep 9, 2009
Loading...

Share This Page