Memory test game program !
Quote:
I want help with this ...
This is the code, and i have taken 4 questions initially... and applied the input method to only question 1 ... i want the input scanner variable of question 1 to be stored in a variable with automatic numbering as the for loops runs till 10 my variable name changes so that i could later call the same question again and compare the answers with if condition ! for example i'm taking 10 inputs for "write 10 colors names" :
i want those inputs.. to be used later again
lets look at it step by step..
1. Show randomly 1 question out of 10.
2. The question's answers should be 10, for example .. write 10 colors, write 10 countries!
3. when the user enters all 10 answers,the program should again display the same question and ask the user to repeat the answers which he/she entered earlier !
4. If the user manages to write the answers in correct sequence in which he entered earlier, the program should add +10 score for each correct sequence answer.
Code :
import java.util.Scanner;
public class Game {
public static void main (String arg[])
{
java.util.Random r = new java.util.Random();
int a = r.nextInt(4);
int abc[] = null;
if (a==0)
{
System.out.println("Write 10 color names: ");
Scanner question = new Scanner(System.in);
for(int i=0; i<10; i++)
abc[i] = question.nextInt();
}
else if (a==1)
{
System.out.println("Write 10 city names: ");
}
else if (a==2)
{
System.out.println("Write 10 contry names: ");
}
else if (a==3)
{
System.out.println("Write 10 vegetable names: ");
}
for (int g=0; g<10;g++)
System.out.println(abc[g]);
}
}
Re: Memory test game program !
Quote:
i want those inputs.. to be used later again
Do you know about ArrayLists or arrays? They are useful for saving input.
Quote:
what am i doing wrong
Please explain.
Can you describe in some detail what you want the program to do?
Write the steps the program must take as a list of simple steps.
Please edit your post and wrap your code with
[code=java]
<YOUR CODE HERE>
[/code]
to get highlighting and preserve formatting.
Re: Memory test game program !
yes i know about arraylist and array ! thats the trick ...
i don't have to use arraylist, array and even hash map :(
any other way ?
Re: Memory test game program !
How much data do you want to save to use later? What type of data: int, String or ???
Can you describe in some detail what you want the program to do?
Write the steps the program must take as a list of simple steps.
Re: Memory test game program !
i have edited the details above ..
user is asked a question, to name 10 things...
those 10 things ... string.. must be later used to compare with .. the next input ..
means the same question is gonna be showed twice !
and i want to match the answers of first question which the user entered ... with the answers of the same question user will entered afterwards ...
for example ...
Q. write ten colors !
Ans:
red
blue
green
yellow
orange
purple
pink
violet
silver
golden...
now the user is asked the same question again ..
write 10 colors names..
Ans ...
now whatever answers user enters , must be compared with the previous answers!
without using arrays and arraylist
Re: Memory test game program !
Quote:
whatever answers user enters , must be compared with the previous answers!
without using arrays and arraylist
That's possbile but would be a not good coding technique. It would be possible to save 10 Strings in one String with some special character between them, but that would be very unnatural coding and a lot more work.
Or the Strings could be written to a file and read back.