Results 1 to 2 of 2
  1. #1
    Mideoan is offline Member
    Join Date
    Feb 2011
    Posts
    7
    Rep Power
    0

    Default Converting Scanner input to JOptionPane

    I would much rather print this out through JOptionPane than to have it displayed on the console. Where do I start with it?

    Java Code:
    import javax.swing.JOptionPane;
    import java.util.Scanner;
    public class DriverExam  {
    	
    	 
    	     public static void main(String[] args)
         {
        // accept keyboard input
           Scanner keyboard = new Scanner(System.in);
           
    	      System.out.println("Enter your answers below.\n");
     
         char[] answers = new char[20];
    
          // request an answer for each question
          for(int i = 0; i < answers.length; i++)
          {
                // get input until input is valid
    	            char input;
    	           
                do
                {
    	                  System.out.print(i + 1 + ". ");
     
                      // get character and make it upper case
                      input = Character.toUpperCase(keyboard.next().charAt(0));
    	            }
                while(input < 'A' || input >'D');
     
    	            // store answer
    	            answers[i] = input;
    	      }
    	 
    	      // print output here
          DriverExamClass driver = new DriverExamClass(answers) {};
    	      System.out.println();
    	      System.out.println("You "+(driver.passed()?"passed" : "did not pass") + ".\n");
    	      System.out.println("Correct: " + driver.totalCorrect() + "\n");
    	      System.out.println("Incorrect: " + driver.totalIncorrect() + "\n");
    	      System.out.println("Questions missed: " + driver.questionsMissed());
    	       
    	  }
    	}

  2. #2
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

Similar Threads

  1. End Scanner int input with text value
    By BillyB in forum New To Java
    Replies: 3
    Last Post: 03-07-2011, 05:13 PM
  2. how to reverse some input from scanner
    By moncur in forum New To Java
    Replies: 24
    Last Post: 11-09-2010, 02:59 PM
  3. Input JOptionPane
    By nic21 in forum AWT / Swing
    Replies: 1
    Last Post: 11-18-2009, 05:32 PM
  4. Scanner input problem
    By slayer_azure in forum New To Java
    Replies: 3
    Last Post: 05-26-2008, 10:49 PM
  5. JOptionPane - input dialog
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-17-2007, 09:09 AM

Posting Permissions

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