• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I write this?  RSS feed

 
Kara Wilimas
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am writing a code in which a user inputs data as a string and that data must be verified as a valid number. A valid number is anything from 0-100. Then all valid numbers are converted into double numbers.

I am having trouble in how to write the validation part of the code.

Is it suppose to be an if, else statement? And if so how is it suppose to be validated?


Thank You.

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You already said that. It will be an if... else statement. What did you try so far? Please post that here. We will use that as the basis to improve and finally arrive at the logic.
 
Kara Wilimas
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So far I have this. Am I finding the array length right? and is the validation correct?

 
Kara Wilimas
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EDIT:

The output is suppose to look like this:

number of valid grades entered: 2
92.5
100
average: 96.25

The listed numbers are to be printed in the reverse ordered they were entered.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will that actually compile? I think you have got confused between = and == as I said in your other thread.
Please go back and alter your thread subject so people looking through the contents have some idea what it is about.
You have got off to a bad start with a single big method. A method should do one thing and you have a method doing about half‑a‑dozen things. Which means you should have about half‑a‑dozen methods. Thenyou can see the logic of what each does, and examine them separately.
Your variable names are not at all clear; you should be able to tell what the variable means by reading it out.
Why have you got a String[]?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!