If your input field isn't empty your code considers it as valid input; I doubt that you want that.
Gotcha, I understand that part... again my Java understanding is very basic. My issue is that if I make that statement false the program doesnt run at all and errors out at this point. Which I reckon means the rest of my code here is all jacked up.
ok I've been working on this all day and here's what I got.... It runs, and I only accept the proper colors, however there is an issue with my if/then and catch statements. If I put the wrong color in first, i.e. Brown, it tells me that is not a valid color. If I put a correct color in i.e. Blue, it still tells me that it is not a correct color and goes to the catch statement and ends the program. If I put Blue in to begin with it works fine and tells me that is a valid color. What am I missing?
.... code removed
Code tags please. :)
Close but not quite. ( not <>)
one mo' 'gin
any input would be welcome
Inside your for loop you don't check for a valid color correctly. The way you have it right now checks it against the original input.
changed the value of the loop to only check for empty string... however now when i run it, it asks me for a color, and if i put the right color in the first time its good. If I put the wrong color in, and then any color the second time it just stops the program. Doesn't error out, just stops running.
code removed .....
im sure there has to be an easier way to do all of this, I appreciate you sticking around and looking it over
Inside your for loop, where are you checking if the color entered is correct?
I am not sure what I am doing with that as far as checking for correctness... I currently have it checking to weed out empty fields, would I add something like this:
code removed ......
i know the above isnt right as far as what to do with the color if it is correct.... I guess thats where my brain is stuck
even without the for loop, which I should only hit if i leave the field empty, the other field is jacked up in the sense that after the initial entry it takes any entry.
Seemingly the only thing I have working is the original return flags and case 1....
since the first check works correctly, you can jost encase your validity checking for the first check in your loop.
hate to sound ignorant but the reason its long and drawn out the way I have it, is because its the only way I understand how to do it at this time. I am working on improving my knowledge, but in the meantime can you offer some suggestions on how to "encase your validity checking for the first check in your loop"?
No problem. :)
Sometimes if you have code that's not working you should take a step back and think only about what you want the code to do and see if you can work it out from there.
Ok so what you want to do is check the users input 3 times. That's just a simple for loop that counts to 3.
Inside the for loop you want to:
1. Ask for input
2. Check if the input is valid
3. Handle true or false accordingly
If it is valid you want to exit the loop
If not, just let the loop continue.
You have the right idea with your for, but its not in the right place.
I would only have the input in one place. Right now you have Input in 3 separate places.
You're really close where it's at right now. I think you actually have too much code.
You have all the elements there that you need, they just need to be rearranged.
Just change your for so that your checking and asking for input is inside it.
(You dont need anything thats in your for right now. Get rid of it.)
This is your input
This is your validity checking:Code:
colorcustomerReturn = JOptionPane.showInputDialog( null, "Please select a color Blue, Black, Green, or Gold" );
And this is where you handle the results:Code:
colorreturnBlue = colorcustomerReturn.equalsIgnoreCase("Blue");
colorreturnGreen = colorcustomerReturn.equalsIgnoreCase ("Green");
colorreturnGold = colorcustomerReturn.equalsIgnoreCase ("Gold");
colorreturnBlack = colorcustomerReturn.equalsIgnoreCase ("Black");
returnFlag = 1;
else if (colorreturnGreen)
returnFlag = 1;
else if (colorreturnGold)
returnFlag = 1;
else if (colorreturnBlack)
returnFlag = 1;
returnFlag = 2;
All of these need to appear only once inside a for loop.Code:
The following variables are unnecessary:
String colorreturnInputMsg, colorInputMsg,
customerColor1, color, customerColor2;
results are no better though... If I insert the original correct color it asks me again it runs the first JOption under "ask for input".... Everything else is not effective either... arrgh