• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Stumped, need inspiration.

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic