PDA

View Full Version : Anyone good with java?



Sheamon
03-05-2002, 06:59 PM
This problem's been driving me nutz for a week. I can't compile my Test_Banking class because I get an error on this line:

myBank.addCustomer("Jane", "Smith", new SavingsAccount(500.0, 0.03));

the error says 'Type Expected' at the first double quote. I've tried removing the quotes, that doesn't work either, it just says 'identifier expected' instead. Here's the member function in the myBank class:

public void addCustomer(String first, String last, Account acct)
{
if(numberOfCustomers <= 9)
{
customers[numberOfCustomers] = new Customer(first, last, acct);
numberOfCustomers++;
}
}

Can anyone else figure out whats wrong? :confused:

DarkAngel
03-05-2002, 08:38 PM
Originally posted by Sheamon
Can anyone else figure out whats wrong? :confused:

Where did you declare "Jane" at? Are you sure it's a string type? The only other thing I can think of is that maybe you can't declare a new function in the argument list of a function. So maybe the "new SavingsAccount(500.0, 0.03)" argument is throwing things off?

Sheamon
03-05-2002, 09:42 PM
Originally posted by DarkAngel
Where did you declare "Jane" at? Are you sure it's a string type?

Here:
public void addCustomer(String first, String last, Account acct)




The only other thing I can think of is that maybe you can't declare a new function in the argument list of a function. So maybe the "new SavingsAccount(500.0, 0.03)" argument is throwing things off?

Nope, I've tried declaring it outside as well and I get the same error. *cries*

DarkAngel
03-05-2002, 10:16 PM
Originally posted by Sheamon

Here:
public void addCustomer(String first, String last, Account acct)


Right, but that's just saying addCustomer takes a string as the first argument. Whatever string you use there, though, don't you have to create it before and initialize it? If Jane is a new string, wouldn't you want to say "new String Jane" or something like that?

Sheamon
03-06-2002, 12:50 PM
yeah, I've declared it earlier. :(

DarkAngel
03-06-2002, 02:52 PM
Originally posted by Sheamon
yeah, I've declared it earlier. :(

Hmm. Could you post how you declared it?

Sorry about not being much help so far.

Sheamon
03-06-2002, 05:23 PM
nevermind, I FINALLY figured it out. I left out the main(String args[]) in the TestBanking class, that caused all the errors. I'm now having this problem: :(

Exception in thread "main" java.lang.NullPointerException