jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Setting Parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Setting Parameters" Watch "Setting Parameters" New topic

Setting Parameters

Fonzworth Campbell

Joined: Nov 17, 2009
Posts: 1
I am doing a small Java program for a smaller scale oyster card.

On my train line i have 20 stations but i accidentally entered 400 in the dialogue box only to find out that it still runs the program,. im unsure of how to set it so only these 20 stations are selected and if another is chosen then a error message is printed.

any help would be much appreciated

thank you

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63536

Welcome to the Ranch.

A few things to help you get started on the best foot.

1) Please be sure to take the time to compose descriptive subjects for your posts; read this for more information.

A title such as "Need Urgent Help" is not useful. What would happen if all posts had such a title?

Please go back and change your post to add a more meaningful subject by clicking the button on your post.

2) Please read this.

Good luck with your question.

[Asking smart questions] [About Bear] [Books by Bear]
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11920

you have to validate what the user inputs. They will be able to input whatever they want. your job is to store it (which I assume you are doing). then you need to test it to see if it's valid. if so, your program may proceed. if it's NOT valid, you can have your program quit, have it say "20 is the largest, I'll use that", you can give them another chance to do it, or anything else you want.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
subject: Setting Parameters
It's not a secret anymore!