Results 1 to 1 of 1

Thread: New User

  1. #1
    TKI5 is offline Member
    Join Date
    Dec 2007
    Posts
    1
    Rep Power
    0

    Default New User

    Dear
    All

    Could anyone help me please i have written a piece of code

    Java Code:
    import javax.swing.JOptionPane;
    
    public class Maths
     {
      int UserID = 0;
      
      float result = 0.0f;
      int countnum = 0;
      int count = 0;
      int countTrys = 0;
     
    public void result ()
    	  {
    	   JOptionPane.showMessageDialog ( null ,"You Got " + (result/countTrys) + "% Right");
    	   JOptionPane.showMessageDialog ( null , "Number of Correct Answers " +count);
    	   JOptionPane.showMessageDialog ( null , "Number of Attempts " +countTrys);
    	  }
     
      public static void main(String[] args)
        {
          Maths m = new Maths (); 
          m.choice();
          m.result ();
        }
       
    
       public void choice ()
    	  {
    	   int userChoice;
               String userChoiceString;
    
    		do
    		  {
    	    userChoiceString = JOptionPane.showInputDialog("Enter your choice [1-5] \n 1.Mulitplication \n 2. Number of Correct answers and percentage \n  5. Exit");
            userChoice = Integer.parseInt (userChoiceString);
     
         if ( userChoice == 1 )
    	   {
       
    		   ++countTrys;
    		   ++count;
    		   multiplication ();
    	   }
    	   else if( userChoice == 2 )
    	   {
                   ++countnum;
                   countnum = count/countTrys;
                   result();
            
           }         
    	              
          }
    	  while ( userChoice != 5 );
    	
    	  }
           
     
       public void multiplication()
        {
            
            int multiplicationData, genNumOne, genNumTwo;
            String selectMultiplication;  
        
            genNumOne = (int) ( Math.random() * 12);
            genNumTwo = (int) (Math.random() * 12);
           
            selectMultiplication = JOptionPane.showInputDialog("What is" + " " + genNumOne + " " + "times" + " " + genNumTwo);
            multiplicationData = Integer.parseInt(selectMultiplication);
      	   if ( multiplicationData == (genNumOne * genNumTwo) )
    	   {
    	     JOptionPane.showMessageDialog ( null ,"Very Good" );
    	     result  = result + 100.0f;
    	   }
    	   else
    		{
    		    JOptionPane.showMessageDialog ( null ,"Wrong Answer" );
    		}
           
           
        }
    }
    but know i am tying to extend the program to keep track of the name of the current user. Add an extra menu item, option 3, to change the user. When a user changes, the name of the new user should be read in and the number of attempts and the number of correct answers should both be reset to 0. I am need to modifiy the code associated with menu item 2 to output the name of the user in addition to the other information.

    Also i need to extend your program to keep track of the top five percentages and the names of the users who achieved them. In order to do this you should use arrays; one to store the percentages and the other to store the names. The two arrays can be initialised with five users each with the name “nobody” and a percentage of 0. Each time that the user changes the user should be added to the high score arrays if they have made more than 10 attempts and their percentage of correct answers is greater than one of the entries in the current top five. Add an extra menu item, option 4, to display the top five high scores and names of the corresponding users.


    Using %12 gives the remainder on dividing the random integer by 12; this could be a psoitvie or negative number in the range 0 – 11. Adding 1 ensures it is from 1 – 12. Using Math.abs ensures that it is positive.

    A variation of one pass of the bubble sort is one way to add a high score in its correct position in the array. If the high score array is in descending order then one way to add a new high score would be as follows. Compare the current score with the last entry in the array. If it is bigger then it should be in the high score table, bubble it to its correct position. Consider a current score of 52% for Joe being added to the following arrays.\:

    Names Liz Adam Henry Sarah Dan
    Scores 84 75 51 49 47
    After first comparison:
    Names Liz Adam Henry Sarah Sarah
    Scores 84 75 51 49 49
    After second comparison:
    Names Liz Adam Henry Henry Sarah
    Scores 84 75 51 51 49
    Now Joe is added
    Names Liz Adam Joe Henry Sarah
    Scores 84 75 52 51 49


    If anyone could help that would be fantastic.

    Thank you all
    Last edited by JavaBean; 12-13-2007 at 06:51 AM. Reason: [code] tag is fixed.

Similar Threads

  1. How to get the User Name
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-04-2008, 03:43 PM
  2. cant take input from user
    By new_1 in forum New To Java
    Replies: 6
    Last Post: 12-25-2007, 08:38 AM
  3. Getting current userís name
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-07-2007, 01:04 PM
  4. How to get the User Name
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 10-04-2007, 10:35 PM
  5. Help user interface
    By carl in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 08:58 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
  •