Jump to content

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

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
21 replies to this topic

#1
funjoke88

funjoke88

    Newbie

  • Members
  • PipPip
  • 22 posts
The application will ask questions like:

What comes after D?

A child is expected to answer the question and the application will inform the child if the answer is correct or wrong. The application will ask a total of 20 questions. After all 20 questions have been answered, the application will display a score (from 0 to 20) to inform the child how many questions he or she answered correctly. The application will also list all the letters that were asked.

The letters tested are from ‘A’ up to ‘Y’. Do not include the letter ‘Z’. The letters are selected randomly. No letters are to be repeated, that is, each letter is only asked once in the 20 questions.

Note: The java.util.Random class can be used to generate random numbers. For example, the following statements may be used to generate a random number from 0 to 4 inclusive:

Random generator = new Random();
int number = generator.nextInt(5);


PLS HELP ME IN THIS QUESTION
IT USE JAVA AND GUI APPLICATION
ANYWAN WHO HAVE THE SOURCE CODE?

Edited by James.H, 16 March 2010 - 02:32 PM.


#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
Because this seriously looks like a school task nobody would tend to help if you don't post what you allready have so far. We help, wo don't do homework.
So post us what you've got so far, please.

#3
Shaddix

Shaddix

    Programmer

  • Members
  • PipPipPipPip
  • 102 posts
this is quite an easy project

the thing you should do is put the alphabet in an array

you can get a letter from an array like this:

String test = alphabetArray[0]; //this will put the letter "a" into test
String test = alphabetArray[1]; //will put "b" into test
...
String test = alphabetArray[25]; //will put "z" into test

now you know you can get letters by numbers

like in your first post, you can generate numbers

so if you put the result of your randomgenerator in the veriable randomNumber, you can use that to get a letter from the alphabet

String test = alphabetArray[randomNumber];

I'm not putting the full sourcecode here, but from what I told you should be able to make a start, that is if you're serious about learning Java

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
A to Y is 25 letters.

Beyond that, what do you have so far? What part of it is confusing?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
Shaddix

Shaddix

    Programmer

  • Members
  • PipPipPipPip
  • 102 posts

WingedPanther said:

A to Y is 25 letters?

was that a reaction on my post? because in an array 0-25 is A-Z, so 26 letters

#6
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
You can't ask 'what's beyond 'Z' to children. It confuses them ;)

#7
Shaddix

Shaddix

    Programmer

  • Members
  • PipPipPipPip
  • 102 posts
true, but you have to have it in your array, else you can't validate the answer for the letter "Y" :D
you just have to make sure your random generator doesn't generate the number 25 or higher

#8
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
okay, you have a good point there :thumbup1:

#9
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts

Shaddix said:

was that a reaction on my post? because in an array 0-25 is A-Z, so 26 letters
It was a response to the OP.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#10
funjoke88

funjoke88

    Newbie

  • Members
  • PipPip
  • 22 posts
Shaddix ,can u give me the code ,because i really dunno how to write ....i am poor in this subject .so pls guide me thanks

#11
Shaddix

Shaddix

    Programmer

  • Members
  • PipPipPipPip
  • 102 posts
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

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

#12
funjoke88

funjoke88

    Newbie

  • Members
  • PipPip
  • 22 posts
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