Need Java Help ASAP

Status
Not open for further replies.
Ok, I've got my first java class now and I know the concepts of what to do, just not how to implement the java code. Can someone help me out with a quick question? I need to Create a class called Payment_Card_DB with an instance variable which is an array of Payment_Cards. This arrays should be initialized with 5 debit and 5 credit cards when an instance of Payment_Card_DB is created.

I need to know how to write the damn array correctly. This is what I did, and have no idea why it doesn't work.

String paymentCards[] = new String[10];
paymentCards[0] = new String("Debit Ron");
paymentCards[1] = new String("DebitMark");
paymentCards[2] = new String("Debit Doug");
paymentCards[3] = new String("Debit Brad");
paymentCards[4] = new String("Debit Matt");
paymentCards[5] = new String("Credit Mike");
paymentCards[6] = new String("Credit Jim");
paymentCards[7] = new String("Credit Fred");
paymentCards[8] = new String("Credit Tom");
paymentCards[9] = new String("Credit Bob");

Thanks
 

OneFootsTheSame

Smack-Fu Master, in training
70
j3 wrote:
yep, the correct declaration is:
String [] Cards = new String [10]
rather than
String Cards[]....

Either declaration is correct. From the language spec, section 10.2:

The [] may appear as part of the type at the beginning of the declaration, or as part of the declarator for a particular variable

Edit: Oh yeah ... there's nothing wrong with the original code snipit posted which compiles fine with javac. If it's not compiling with another tool, it would be a problem with it.

[This message was edited by OneFootsTheSame on November 06, 2001 at 16:29.]
 
Status
Not open for further replies.