Sujath Mohammed wrote:For some reason my validation seem to not work properly where if i type an element that's not in the array it repeats the word invalid
Jeff Verdegan wrote:
Sujath Mohammed wrote:For some reason my validation seem to not work properly where if i type an element that's not in the array it repeats the word invalid
That "some reason" is because that's exactly what you're telling it to do. Your loop says, "For every element in the winners array, either print out the corresponding element in the years array (if the winners element matches the input), or print out 'invalid' (if it doesn't match the input)."
There's nothing there that says anything about "if the input wasn't found at all in the winners array." You need to work out how to do that without any reference to Java. Just work out--clearly and precisely--how to to it "by hand." Then you can translate those steps to Java.
It's an odd requirement though. What you're saying is, if somebody enters a team that has never won, the response will be "Invalid," instead of something more sensible like, "That team has never won."
And finally, I'll note that the winners/years parallel arrays is a horrible way to manage this data.
Sujath Mohammed wrote:You see i have no choice its the requirement of my assignment to use parallel arrays
Junilu Lacar wrote:I'm curious about your "requirements" though. Would you care to share the exact text of the problem as it was given to you by your instructor?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Junilu Lacar wrote:I'm curious about your "requirements" though. Would you care to share the exact text of the problem as it was given to you by your instructor?
I too would be curious to see the text of the problem exactly as it was given to you; because unless it says that you must use the two arrays that were given to you throughout your program, then you're doing it wrong (or at least you're making an awful lot of work for yourself).
This is now the 3rd thread you've started on this same subject (perhaps you didn't like the advice you were given in the previous ones), and Campbell already hinted to you in your second one how you could do it better - create a Winner class that contains both team name and year.
You could still put those in an array, and the whole business then becomes a LOT simpler.
Winston