Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes HOTEL ATTRIBUTES & CONSTRUCTOR Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java


Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
Hi, just checking for advise:-
1.An attribute for customer name would be String?
2.Attribute for phone number(UK) would be int?
3.Attribute for credit card number would be int?
Is that right?(I am no good at java!)
A constructor which sets just the name attribute would be considered as a default constructor? Is that correct???
Would be very grateful is somebody could help me. Thank You
Donald R. Cossitt
Ranch Hand

Joined: Jan 31, 2003
Posts: 401
I would think you would probably want a String for each in that spaces and '-' are usually found in each of those.
However if you used no spaces for your phone numbers or credit card numbers you would probably use (long) simply because any number over 4 bytes (32 bits) or 2147483647 in size will create an exception. So, if your (us) phone number was 214 748 3647 (spaces for clarity) you would be 0k. But what if your phone was (us) 217 748 3648 ? How would you identify prefix for UK call: (020) 7225 6506 - the '0' would not appear in your (int) or (long) besides being too big for (int).
Also credit card digits are 20 or more.
See this tutorial
Also look at this for your
constructor stuff.
[ April 18, 2003: Message edited by: Donald R. Cossitt ]

Joel McNary

Joined: Aug 20, 2001
Posts: 1824

You would want strings for all three attribtues. The length argument aside (which is valid), conceptually a phone number is not a number--it is a sequence of digits.
For example, if you integrated your phone system with your application (so that you could dial phone numbers from within the applcation--call centers use this technology), you want the phone to dial "one" "eight" "zero" "zero" "five" "five" "five" "one" "two "one" "two" instead of attempting to dial eighteen billion, five million, five hundred fifty-one thousand, two hundred twelve (18005551212, to use a US example).
The same is true with credit cards; they are a string of digits instead of a number.
A default constructor is one that takes no arguments.
public Customer(){} is a default constructor;
public Customer(String name){} is not a default constructor.
[ April 18, 2003: Message edited by: Joel McNary ]
[ April 18, 2003: Message edited by: Joel McNary ]

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
Thank you. You have both been very helpful and have given me more knowledge of the attributes. I will try to approach it by making all three attributes as Strings.
I agree. Here's the link:
It's not a secret anymore!