aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S: Customer ID (owner) exact 8 digits or not? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S: Customer ID (owner) exact 8 digits or not?" Watch "B&S: Customer ID (owner) exact 8 digits or not?" New topic
Author

B&S: Customer ID (owner) exact 8 digits or not?

Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi,

my assignment state about the owner field in my data file:


The id value (an 8 digit number) of the customer who has booked this. ... The system you are writing does not interact with these numbers, rather it simply records them ...


I simply check whether the input in the customer id text field of my GUI is 8 digits. If it's more than that I throw a message to the user.

I don't care whether the user enter a numerical or alpha-numerical value. But I have to take care that there is a 8 digits input which goes down to the data file otherwise the writeBytes process to the data file becomes messy.

So I have two options:

1) Force the user to enter a 8 digit number
2) Pad the user input with white spaces til 8 digits

What do you prefer?

Regards,
Darya


SCJP, SCJD, SCWCD, SCBCD
Zee Ho
Ranch Hand

Joined: Jul 20, 2004
Posts: 128
I prefer the point 2. but I don't think the validation is very necessary for the project. For my case, I just cut the string to 8 if user's input value exceeds the range or pad space if user's input is less than 8. since in my mind, there's surely a lot of things need to be validated If we want to. In order to make the things simply, I choose this way. what about you, ranchers?
[ April 28, 2005: Message edited by: Zee Ho ]

SCJP 1.4<br />SCWCD 1.3<br />SCJD<br />SCBCD<br />IBM Xml Cert in progress
Jared Chapman
Ranch Hand

Joined: Feb 23, 2004
Posts: 81
I just made sure there was some input, and that the input was made up entirely of numbers, and that there were no more than 8 of them. In the case where there are less than 8 digits entered, i add the appropriate number of leading 0's.


B.S. University of Wisconsin<br />SCJP 1.4 (85%)<br />SCJD 1.4 (92%) B&S Contractors
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
That's 2:0 for padding . Honestly I've forgotten how I have to pad a String.

Let's say I have:

and want to pad it with white spaces to

Any hints are welcome.

Regards,
Darya
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Of course I can write some lines to implement it but I am looking for a single line solution.

Isn't the JDK offering something for padding?

Regards,
Darya
Olena Golub
Ranch Hand

Joined: Jan 17, 2005
Posts: 113
Hi Darya,

I am not sure, that there is something defined for padding in Java.
My idea is to define the method. You can use this method also for another elements from the records:


Regards, Olena
[ April 28, 2005: Message edited by: Olena Golub ]

SCJP 1.4<br />SCJD 1.4 (in progress)
Olena Golub
Ranch Hand

Joined: Jan 17, 2005
Posts: 113
Or this one, its more universal:

Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi Olena ,

it seems that the JDK is really not offering something for padding a String .

So I am going for a pad method similar to yours.

Thanks,
Darya
Danny Martin
Greenhorn

Joined: Aug 26, 2005
Posts: 5
Hi all,
why not use something like this?



Will the junior programmer be able to understand a combination of Arrays.fill and System.arrayCopy without getting confused?

Hope this can help.
DM
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11523
    
100

Hi Darya,
Of course I can write some lines to implement it but I am looking for a single line solution.
Perhaps:Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Samuel Pessorrusso
Ranch Hand

Joined: Jul 21, 2005
Posts: 164
I did something like Andrew said.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: B&S: Customer ID (owner) exact 8 digits or not?