Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HOTEL ATTRIBUTES & CONSTRUCTOR

 
Rupinder Bains
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rupes.x
 
Donald R. Cossitt
buckaroo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
HTH
doco
[ April 18, 2003: Message edited by: Donald R. Cossitt ]
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Rupinder Bains
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic