If you know computers check this out..
Collapse
Recommended Videos
Collapse
X
-
Rose City 'Til I Die
Duuuuuuuvvvvaaaaaaaal
Hokie Hokie Hokie Hy
Member: OS Uni Snob Assoc.
OS OT Post Champ '11
Twitter: @TheGIGGAS_OS
Xbox Live: TheGIGGAS
3DS: 1349-7755-3870
-
Re: If you know computers check this out..
Ok, first off, I was looking at your program again and I see why you had the do whiles around each JOptionPane and I see why you need them (to ask again if the user enters an invalid number). So I'm sorry if I steered you wrong on that. That works good
Ok, now for the help you actually asked for
I don't think you need any kind of ActionListener to activate the switch statement. The way you have your code set up, after you receive the number that maps to which math operator you use (after the do while loop that the JOptionPane is within to verify that the number is between 1 and 4), this is where you do the switch statement. The switch statement will calculate your answer and store it in your results double, then you display that answer in another JOptionPane (just a simple informational pop-up like you used to tell the user that an input was incorrect). After that, ask the user if they won't to go again, and either go again or exit.Last edited by aukevin; 10-16-2007, 09:34 AM.
Atlanta Braves - Auburn Tigers - Nashville Predators
Comment
-
Re: If you know computers check this out..
here is where I am so far.Attached FilesPSN: The_TechNinja
Check me out on YouTube as well: http://tinyurl.com/lqd6s9jComment
-
-
Re: If you know computers check this out..
Still looks like you are on the right track. (HINT: You might want to check your variables in your if statement when verifying the second number entered.) You also still need to declare the results double at the top and you are missing some closing curly braces at the end of the program.
I don't see where you are going with the operation String, I don't see why you need that and what you gain in the switch statement by trying to assign it to something. You have that results value, just display it in a JOptionPane after you close the switch statement.
Your switch statement syntax looks good now
Atlanta Braves - Auburn Tigers - Nashville Predators
Comment
-
Re: If you know computers check this out..
Kevin,
Thanks for all of your help, without you I dont know where I'll be in this program, PM your pay pal info, and i'll give you donation for a cup of coffee or something. This is major headace for me.
Now, the reason im putting the operation string in there is because, I'm not sure how to link the cases to the mathmaticall operation. This is where i'm stuck at.
Also, I'm not sure if i have my JOption pane to display the results is in the correct spot or even the correct format.
Because im my program it's only going to inset the second number, I seem to cannot get any further.PSN: The_TechNinja
Check me out on YouTube as well: http://tinyurl.com/lqd6s9jComment
-
Re: If you know computers check this out..
LOL, don't worry about the paypal. I used to bug my professors/teaching assistants up the wall with programming questions when I first started out.
Now, the reason im putting the operation string in there is because, I'm not sure how to link the cases to the mathmaticall operation. This is where i'm stuck at.
Originally posted by from your codes = JOptionPane.showInputDialog("Select a math operation: \n 1: Add \n 2: Subtract \n 3: Multiply \n Divide");
choice = Integer.parseInt(s);
Originally posted by from your code againswitch (choice)
{
case 1:
{
results = (num1 + num2);
operation = addition;
break;
}
case 2:
{
results = (num1 - num2);
operation = subtraction;
break;
}
case 3:
{
results = (num1 * num2);
operation = multiplication;
break;
}
case 4:
{
results = (num1 / num2);
operation = division;
break;
}
{
The way your program is right now all you have to do (except for fixing missing or wrong direction curly braces and some other minor problems) is display the results variable in a new JOptionPane. And then loop it again to run the program again by possibly using the method I hinted at last week with a stop variable.Last edited by aukevin; 10-16-2007, 10:56 AM.
Atlanta Braves - Auburn Tigers - Nashville Predators
Comment
-
Re: If you know computers check this out..
I'm seeing what your saying. Now my question is, I am unsure where should i put my JOptionpane at. before the switch or after?
Because as of right now after i enter my second number the option does not come up. I think the coding is correct, now i just need to to display up. Ive tried moving it around, with trial and error but I am seeing the same resultsPSN: The_TechNinja
Check me out on YouTube as well: http://tinyurl.com/lqd6s9jComment
-
Re: If you know computers check this out..
I'm seeing what your saying. Now my question is, I am unsure where should i put my JOptionpane at. before the switch or after?
Because as of right now after i enter my second number the option does not come up. I think the coding is correct, now i just need to to display up. Ive tried moving it around, with trial and error but I am seeing the same results
Your JOptionPane that asks for the math operator must go before the switch statement because it fills in the choice variable which is needed for the switch statement. That's how you have it in the code you posted, so that's good. You need to use the same do while loop technique you used for the first two JOptionPanes around the JOptionPane that asks for the math operator just in case the user doesn't enter 1-4. You need to check that condition just like you did the 1-35 condition for the two numbers that are first inputted.
After you get that taken care of, your switch statement is fine except the closing curly brace for the switch that is facing the wrong way (and take out that operation equals stuff because I don't think you need it (comment it out if you don't want to delete it yet).
However, I don't get how your code is compiling because you haven't declared your results variable or those variables you are trying to set equal to the operation String (which I don't think you need anyway). You have some curly brace issues too. So I'm not sure how you are even able to get the first two pop-ups to show up when it isn't compiling.
Anyway, once you fix your syntax problems (curly brace issues) or not declaring variables (like the results one), I would put a System.out.println(results) in the code right after you close the switch instead of the System.exit(0) so that you can print out and see the right computation. After you see that you can print out the right value, you can put that results value on a JOptionPane.
Atlanta Braves - Auburn Tigers - Nashville Predators
Comment
-
Re: If you know computers check this out..
Declearing results as a varible is as simple as:
// Declare Variables
double num1;
double num2;
int choice;
String s;
results;
but i get an error stating that results is not a statement.PSN: The_TechNinja
Check me out on YouTube as well: http://tinyurl.com/lqd6s9jComment
-
Re: If you know computers check this out..
double results = 0;
Atlanta Braves - Auburn Tigers - Nashville Predators
Comment
-
Re: If you know computers check this out..
double results?
or INt results?
I've tried both, and still I cannot get past the 2nd phrase of numbers.
here is where i'm at.Attached FilesPSN: The_TechNinja
Check me out on YouTube as well: http://tinyurl.com/lqd6s9jComment
-
Re: If you know computers check this out..
You are also missing a closed curly brace at the end. After that, it should compile.
Atlanta Braves - Auburn Tigers - Nashville Predators
Comment
-
Re: If you know computers check this out..
It needs to be a double because it could possibly store the results of a division. You need to initialize it to zero also, otherwise you will get a compile error because it would never have a value assigned to it before it is printed out at the end in the case that the results variable never was assigned a value in the switch statement.
You are also missing a closed curly brace at the end. After that, it should compile.
One more request my good man, how do i JOption pane the results?PSN: The_TechNinja
Check me out on YouTube as well: http://tinyurl.com/lqd6s9jComment
-
Re: If you know computers check this out..
You would use a JOptionPane just like you did when you were showing an error for when the user entered a bad value for the numbers.
Originally posted by from your codeJOptionPane.showMessageDialog(null, "Please enter a number between 1 and 35.", "A Wrong Number Was Entered", JOptionPane.ERROR_MESSAGE);
For example if you have these two statements:
String name = "Kevin";
String s1 = “My name is” + name;
If you said: System.out.println(s1);
You would get: "My name is Kevin"
So if I wanted a JOptionPane that showed my string above, it would be:
JOptionPane.showMessageDialog(null, "My name is "+name, "This is how you append values to a String", JOptionPane.INFORMATION_MESSAGE);
So the you need to make a string that displays the results variable just like how above shows the name variable.
Atlanta Braves - Auburn Tigers - Nashville Predators
Comment
Comment