• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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

 
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Olena Golub
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or this one, its more universal:

 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Darya,

Of course I can write some lines to implement it but I am looking for a single line solution.

Perhaps:Regards, Andrew
 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did something like Andrew said.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic