Results 1 to 6 of 6
  1. #1
    Quizzle23 is offline Member
    Join Date
    Feb 2011
    Posts
    34
    Rep Power
    0

    Default 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

  2. #2
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    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

  3. #3
    baloda is offline Member
    Join Date
    Nov 2010
    Location
    New Delhi
    Posts
    50
    Rep Power
    0

    Default

    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!!!

  4. #4
    Quizzle23 is offline Member
    Join Date
    Feb 2011
    Posts
    34
    Rep Power
    0

    Default

    @ baloda:

    Thank you so much that worked!!!!! :)

  5. #5
    Quizzle23 is offline Member
    Join Date
    Feb 2011
    Posts
    34
    Rep Power
    0

    Default How to use System.out.printf

    Hi,

    Is it possible to use System.out.printf in JOptionPane? If so how?:D

    Thanks

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    No. System.out sends the output to standard output and not the JOptionPane (unless you change it but that is a bad idea). Take a look at the String class and see what methods it has. HINT: it has one that does the exact same thing as printf does.

Similar Threads

  1. Probmlem help fast
    By matteo263 in forum New To Java
    Replies: 5
    Last Post: 12-03-2010, 09:40 AM
  2. Fast Help Plz ..
    By Hamodi18 in forum New To Java
    Replies: 6
    Last Post: 07-16-2010, 05:24 AM
  3. how fast?
    By abdullahansari in forum New To Java
    Replies: 4
    Last Post: 06-30-2010, 03:17 AM
  4. Help me fast!
    By Manikyr in forum New To Java
    Replies: 4
    Last Post: 03-16-2009, 07:43 AM
  5. pls help me fast!
    By rexson98 in forum New To Java
    Replies: 10
    Last Post: 10-15-2008, 12:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •