Closed Thread
Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 22

Thread: use GUI application to be used to test Kindergarden children on the alphabet (‘A’-‘Z

  1. #11
    Shaddix's Avatar
    Shaddix is offline Programmer
    Join Date
    Apr 2009
    Location
    Westmalle, Antwerpen, Belgium, Belgium
    Posts
    104
    Rep Power
    11

    Re: use GUI application to be used to test Kindergarden children on the alphabet (‘A

    normally we don't give you the code here, but as it's a simple program it might be easier to explain everything by code

    Code:
    import java.util.Random;
    import java.util.Scanner;
    
    public class Alphabet {
    	//We declare the random generator globally
    	private Random generator = new Random();
    	
    	//Here we will remember what the index was of the letter we asked
    	private int askedLetterIndex;
    	
    	//Here we declare the alphabet
    	private char[] alphabet = {'a','b','c','d','e','f','g','h'
    			,'i','j','k','l','m','n','o','p','q'
    			,'r','s','t','u','v','w','x','y','z'};
    	
    	//This function will get you a random number from our alphabet
    	private char getRandomLetter(){
    		askedLetterIndex = generator.nextInt(24);
    		return alphabet[askedLetterIndex];
    	}
    	
    	//This will check the answer of the user, it returns True if the answer was correct and False if it was incorrect
    	private Boolean checkAnswer(char answer){
    		if (alphabet[askedLetterIndex + 1] == answer){
    			return true;
    		}else{
    			return false;
    		}
    	}
    	
    	//This method will do the test 
    	//This is a console application, so for a GUI application you'll have to rewrite this method
    	public void doTest(){
    		//The scanner will be used to read the answer of the user
    		Scanner in = new Scanner(System.in);
    		
    		//Here we will stock the answer of the user
    		char answer;
    		
    		//This will ask the user a letter for 10 times
    		for(int i = 0; i < 10; i++){
    			System.out.println("What letter comes afther '" + getRandomLetter() + "' ?");
    			answer = in.next().charAt(0);
    			
    			if(checkAnswer(answer)){
    				System.out.println("Correct!");
    			}else
    				System.out.println("Wrong!");
    		}
    	}
    	
    	//Run the program
    	public static void main(String[] args) {
    		Alphabet a = new Alphabet();
    		a.doTest();
    	}
    }
    This is a console application, but it shows you how to do this kind of programs

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #12
    funjoke88 is offline Newbie
    Join Date
    Jul 2009
    Posts
    22
    Rep Power
    0

    Re: use GUI application to be used to test Kindergarden children on the alphabet (‘A

    this is the part of code only right ?but i not sure how to use gui application for this question ,can you help me pls

  4. #13
    funjoke88 is offline Newbie
    Join Date
    Jul 2009
    Posts
    22
    Rep Power
    0

    Re: use GUI application to be used to test Kindergarden children on the alphabet (‘A

    hello can you use GUI application to write out the code for this question ?pls help me !

  5. #14
    Join Date
    May 2009
    Location
    Belgium
    Posts
    1,881
    Rep Power
    24

    Re: use GUI application to be used to test Kindergarden children on the alphabet (‘A

    Common, show some effort.
    Give us the code you would use to create a GUI class. it will basicly need 2 components, a JLabel and a JTextfield. Every System.out.println() should be turned into a method like FrameClass.setLabelText(text)

    And the "in.next()" is replaced by a JTextfield.

    To let the textfield react on the user's 'ENTER' use:
    Code:
    textfield.addKeyListener(new KeyListener(){
            public void keyPressed(KeyEvent e){/*Empty*/ }
            public void keyReleased(KeyEvent e){/*Empty*/}
            public void keyTyped(KeyEvent e){
                    if(e.getKeyChar() == KeyEvent.VK_ENTER){
                        String text = textfield.getText();
                        alphabet.checkAnswer(text)
                    }
                }
    
            });
    Or you could use a button instead

  6. #15
    funjoke88 is offline Newbie
    Join Date
    Jul 2009
    Posts
    22
    Rep Power
    0

    Re: use GUI application to be used to test Kindergarden children on the alphabet (‘A

    hello may i know is this a full source code for gui application in this question ?thanks for helping me ...

    Code:
    textfield.addKeyListener(new KeyListener(){
            public void keyPressed(KeyEvent e){/*Empty*/ }
            public void keyReleased(KeyEvent e){/*Empty*/}
            public void keyTyped(KeyEvent e){
                    if(e.getKeyChar() == KeyEvent.VK_ENTER){
                        String text = textfield.getText();
                        alphabet.checkAnswer(text)
                    }
                }
    
            });
    Last edited by ZekeDragon; 03-22-2010 at 06:30 PM. Reason: Please use [code] tags (the # button) when posting code.

  7. #16
    Join Date
    May 2009
    Location
    Belgium
    Posts
    1,881
    Rep Power
    24

    Re: use GUI application to be used to test Kindergarden children on the alphabet (‘A

    No, it only adds a listener to a textfield so when you are typing in the textfield and push 'Enter' something happens.

  8. #17
    funjoke88 is offline Newbie
    Join Date
    Jul 2009
    Posts
    22
    Rep Power
    0

    Re: use GUI application to be used to test Kindergarden children on the alphabet (‘A

    can i have the full code of it ?because i really dunoo how to do this question ,shaddix

  9. #18
    funjoke88 is offline Newbie
    Join Date
    Jul 2009
    Posts
    22
    Rep Power
    0

    Re: use GUI application to be used to test Kindergarden children on the alphabet (‘A

    hello may i know the solution of gui application ?i really need the source code of this question .pls help me shaddix

  10. #19
    funjoke88 is offline Newbie
    Join Date
    Jul 2009
    Posts
    22
    Rep Power
    0

    Re: use GUI application to be used to test Kindergarden children on the alphabet (‘A

    hello ,the code u given are tested .but the alphabet is repeated for some .and the question request that no alphabet is to be repeated .so how 2 solve this problem ?shaddix thanks

  11. #20
    Join Date
    May 2009
    Location
    Belgium
    Posts
    1,881
    Rep Power
    24

    Re: use GUI application to be used to test Kindergarden children on the alphabet (‘A

    Got this from another post on the forums. Fits so perfectly:
    Code:
    While( !User.hasAnswer )
    {
         User.askQuestion();
    
         if( User.postCode && User.putForthEffort )
         {
              CodeCallMembers.Help();
              User.hasAnswer = true;
         }
         else
         {
              CodeCallMembers.Laugh();
         }
    }

Closed Thread
Page 2 of 3 FirstFirst 123 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. get numbers and alphabet using php
    By lol33d in forum PHP Development
    Replies: 4
    Last Post: 08-25-2011, 11:44 AM
  2. Finding All Children
    By BlaineSch in forum Database & Database Programming
    Replies: 4
    Last Post: 11-30-2009, 01:04 PM
  3. Online Test Application Help.
    By sat147 in forum C# Programming
    Replies: 12
    Last Post: 09-19-2009, 08:53 AM
  4. Loose coupling and parents/children/related
    By RedShift in forum General Programming
    Replies: 4
    Last Post: 12-06-2008, 10:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

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