File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Stumped, need inspiration. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Stumped, need inspiration." Watch "Stumped, need inspiration." New topic

Stumped, need inspiration.

Jesse Crockett
Ranch Hand

Joined: Feb 03, 2005
Posts: 129
Please glance over the following code. It is basically just a skeleton at about 1/3 complete. I am to give the Customer class additional functionality to handle multiple accounts, for which I can think of no better than an int[10] array at new construction. And then I am to supply functionality for customers with shared accounts. Helpful suggestions are greatly appreciated.

edit: I know that it says Midterm and that it's obviously homework, but i've dropped the course and the professor is giving me a chance to get a waiver for the course if i do all this work. i am not asking anybody to do all the work, just point the right direction. believe me, i'd rather be programming Swing. :-)

[ December 09, 2006: Message edited by: Jesse Crockett ]
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Why an array? Far better to use a List or Set of accounts.
But do you really want such a close tie between Customer and Account.
As you indicate you want shared accounts it might be better to have another way of mapping them, like a Bank class which holds a Map of Customers with a List or Set of Accounts per customer.

Jesse Crockett
Ranch Hand

Joined: Feb 03, 2005
Posts: 129
The Prof specifies "an array of accounts" but no more than that. I don't know about Lists and Sets. I'm still looking at this code and going nowhere. It is really frustrating. Now I can see that the Customer constructor is flawed.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
int[] is the type for an array of ints. An array of Accounts would have the type Account[].
Since both type of accounts have a common superclass you might be able to group both
account types in the same data structure; you just have to play around with it and see how
to make it do what you want.
As far as the arrays, you can open the account with a zero–length array of accounts
and add each new account to this array as they arrive. For example, say I have an array of
Rectangles named "rects" and I want to add another Rectangle to it. I could make a
method in which I could do this:
Jesse Crockett
Ranch Hand

Joined: Feb 03, 2005
Posts: 129
I am trying to make a piecemeal that will get a passing mark --- just trying to get something to turn in. Right now I am confused by the errors pertaining to my use of references "ca" and "ca1" right after the for loop in the BankTest constructor:

[ December 09, 2006: Message edited by: Jesse Crockett ]
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Fields that are defined inside of a method (like sa, ca and ca1) need to be initialized before they are used, and the compiler needs to be sure of that. Note that it doesn't complain about sa, because that is definitely initialized before it is used, but ca and ca1 are used in spots where they have not necessarily been initialized (e.g., if the switch took case 0).

The solution is to assign them something, e.g. null.
[ December 09, 2006: Message edited by: Ulf Dittmer ]
I agree. Here's the link:
subject: Stumped, need inspiration.
jQuery in Action, 3rd edition