Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

Strange error message

Thread view: 
aver24@hotmail.com - 26 Nov 2005 04:18 GMT
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;
}
Rhino - 26 Nov 2005 05:18 GMT
> 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)  {
[quoted text clipped - 36 lines]
>  private int balance = 0;
> }
Lee Weiner - 26 Nov 2005 05:23 GMT
>I'm new to programming. When I compile this program, I get this error
>message:
[quoted text clipped - 12 lines]
>  }
>}

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
Roedy Green - 26 Nov 2005 16:46 GMT
use:
>    BankAccount alice = new BankAccount(),

declaration:
>  public BankAccount(int initialBalance)  {

Don't you see the mismatch?
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.