Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Strange error message

Reply
Thread Tools

Strange error message

 
 
aver24@hotmail.com
Guest
Posts: n/a
 
      11-26-2005
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;
}

 
Reply With Quote
 
 
 
 
Rhino
Guest
Posts: n/a
 
      11-26-2005

<> wrote in message
news: oups.com...
> 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;
> }
>



 
Reply With Quote
 
 
 
 
Lee Weiner
Guest
Posts: n/a
 
      11-26-2005
In article < .com>, 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
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      11-26-2005
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange effects using the email.message.Message class Rogério Brito Python 1 09-09-2009 04:19 AM
pylab strange error message ajikoe@gmail.com Python 0 04-22-2005 09:43 AM
Strange news.individual error message? Rifleman Computer Support 12 02-06-2004 12:42 AM
Apache soap package GetStock sample get strange error message jack Java 0 01-22-2004 04:31 PM
Strange error message at client Robert Wehofer ASP .Net 1 11-17-2003 06:40 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57