• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

constructor with array type.

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

how can i make the accNo in class Record can store two accNo?
[ October 24, 2003: Message edited by: brian yuen ]
[ October 24, 2003: Message edited by: brian yuen ]
[ October 24, 2003: Message edited by: brian yuen ]
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


how can i make the accNo in class Record can store two accNo?

try it like this

then it should work
[ October 24, 2003: Message edited by: Oliver Refle ]
[ October 24, 2003: Message edited by: Oliver Refle ]
 
brian yuen
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i still can't work it out
here is what i want
://take the cusomter name, and account Id
addRec.add(new Account(name, Id);
output like
brian, 123
//take another account no
addRec.add(new Account(Id));
output then like
brian, 123, 321
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Brian
Just to be clear - are you trying to allow the 'Record' class to hold references to more than one account? (By the way, you have the name of the class as 'Record', but your constructors are for a class called 'Account' - the names should tie up).
If so, you need to have a member in the Record class of an appropriate data structure - I would suggest using an ArrayList (see API docs for details). Rather than passing in the name and account number to the Record constructor, pass in the name (String) and an object of type List (holding the accounts). So, your constructor's signature will now look like:

You could then add an 'addAccount(String newAccount)' method, which adds the 'newAccount' to the ArrayList, if you need to add further accounts to the customer's record later on (i.e. after construction).
You might also want to take a minute to think about how you are naming your classes/methods/variables - perhaps a better name for the 'Record/Account' class would be 'Customer', or 'AccountHolder', etc.? But mostly, you need to have a clear idea of what that class is for - does it represent a customer, or an account? Right now you seem to be mixing the 2.
Hope this helps
Michael
 
brian yuen
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for all your suggestion.
but the problem is that,
the construtor take 3 args,
1. If the customer choose open account, it's like
take a customerId, customerName, accountNo as args
if (customerId not in the record)
add customerId, customerName, accountId to Record
the output would look like
1, Brian, 12343434

2. when a cusomter choose open a account (a customer can has two account)
take a customerId, customerName, accountNo as args
if (customerName IS IN the record)
add accountNo under its cusotmerId( i just need to acc accountNo to Record)
1,Brian, 12343434, 11112222(so the cusomter now has two account)
so i thought i need 2 constructor, what's wrong withthe design
[ October 24, 2003: Message edited by: brian yuen ]
[ October 24, 2003: Message edited by: brian yuen ]
 
Michael Fitzmaurice
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brian
I think you need to draw the distinction between creating instances of your class and creating new accounts for an existing customer. If you have a 'Customer' class, each instance can represent 1 existing customer. Now, each customer may have 1 or more accounts, so you need to store all of a customer's accounts in a dynamic data structure like an ArrayList (this would be a member of the 'Customer' class). Don't use a String or String array to hold a customers account(s). If you use a String, you limit the customer to one account. If you use a String array, you will have to constantly resize and remap it whenever a customer opens a new account. Another benefit is that you can also create instances of a customer with no accounts if need be, plus you would only need 1 constructor.
You may also store all customers in another ArrayList, but don't confuse storing customers with storing account details for one customer. If somebody is opening a new account, you have 2 scenarios - either
1 - they already have an account, in which case there should be an existing Customer object for that client, and you would then call a method on the object (e.g. addAccount, or something like that) which would add a new String to the ArrayList member of that object
or
2 - they have no existing account, in which case you will need to construct a new Customer object for that new client
I think maybe what you are getting at is that when somebody wants to open an account you need to check if they already have one. If so, that means a search through all Customer objects to see if one matches. If there is no match, construct a new Customer and add it to the container for customers.
Perhaps you could post your instructions here, so that I can be sure what it is you are trying to do?
Michael
 
brian yuen
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much,

that should be working....i think ,
[ October 24, 2003: Message edited by: brian yuen ]
[ October 24, 2003: Message edited by: brian yuen ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic