Results 1 to 6 of 6
Thread: JOptionPane: HELP FAST!!!
- 02-03-2011, 05:27 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 34
- Rep Power
- 0
JOptionPane: HELP FAST!!!
Hello Everyone,
I am doing a mini program for class using JOptionPane. It complies correctly and runs almost correctly. The assignment is to write a program that asks the user to enter 3 test scores. The program should display each test score, as well as the average. I am able to create this except for the fact what ever score the user enters in for the last test (Test 3), is what shows for all three test when it notifies the user of the scores entered for all test. How can I change it so the Pane that displays all three test scores actually displays all 3 scores entered and not the last one. I have placed the code below if that helps and you can email me for screen shots. Please help :confused: quizzle23@aol.com
Java Code:import javax.swing.JOptionPane; public class Question10 { public static void main (String [] args) { String inputString; String name; int test1; int test2; int test3; double test1a; double test2b; double test3c; double average; inputString = JOptionPane.showInputDialog("What did you score on" +" Test 1?"); test1 = Integer.parseInt(inputString); inputString = JOptionPane.showInputDialog("What did you score on" +" Test 2?"); test2 = Integer.parseInt(inputString); inputString = JOptionPane.showInputDialog("What did you score on" +" Test 3?"); test3 = Integer.parseInt(inputString); test1a = Double.parseDouble(inputString); test2b = Double.parseDouble(inputString); test3c = Double.parseDouble(inputString); average = (test1a + test2b + test3c)/ 3; JOptionPane.showMessageDialog(null," Hello your score on your" + " first test was:" + test1a + "." + " Your score on your second test " + " was:" + test2b + "." + " Your score" + " on your third test was:" + test3c + "."); JOptionPane.showMessageDialog(null,"Your average test score is:" + average + "."); } }
Let me know if you can not read that it is a cut and paste lol
- 02-03-2011, 05:47 AM #2
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
You are parsing the last input using inputString instead of test1, test2 and test3 that is why the output is only test3 value because that was the last value of input string.
Just change the one you parsing from inputString to test1,test2 or test3.
Goodluck
- 02-03-2011, 05:56 AM #3
Member
- Join Date
- Nov 2010
- Location
- New Delhi
- Posts
- 50
- Rep Power
- 0
ur using single string variable to get input for three inputs and it holds only last one when u want to use that.
change it like this.
inputString = JOptionPane.showInputDialog("What did you score on" +" Test 1?");
test1 = Integer.parseInt(inputString);
test1a = Double.parseDouble(inputString);
inputString = JOptionPane.showInputDialog("What did you score on" +" Test 2?");
test2 = Integer.parseInt(inputString);
test2b = Double.parseDouble(inputString);
inputString = JOptionPane.showInputDialog("What did you score on" +" Test 3?");
test3 = Integer.parseInt(inputString);
test3c = Double.parseDouble(inputString);
good luck!!!
- 02-03-2011, 08:55 PM #4
Member
- Join Date
- Feb 2011
- Posts
- 34
- Rep Power
- 0
@ baloda:
Thank you so much that worked!!!!! :)
- 02-03-2011, 11:09 PM #5
Member
- Join Date
- Feb 2011
- Posts
- 34
- Rep Power
- 0
How to use System.out.printf
Hi,
Is it possible to use System.out.printf in JOptionPane? If so how?:D
Thanks
- 02-03-2011, 11:16 PM #6
Similar Threads
-
Probmlem help fast
By matteo263 in forum New To JavaReplies: 5Last Post: 12-03-2010, 09:40 AM -
Fast Help Plz ..
By Hamodi18 in forum New To JavaReplies: 6Last Post: 07-16-2010, 05:24 AM -
how fast?
By abdullahansari in forum New To JavaReplies: 4Last Post: 06-30-2010, 03:17 AM -
Help me fast!
By Manikyr in forum New To JavaReplies: 4Last Post: 03-16-2009, 07:43 AM -
pls help me fast!
By rexson98 in forum New To JavaReplies: 10Last Post: 10-15-2008, 12:20 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks