Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Memory test game program !

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Memory test game program !

    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.

     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]);
     
     
     
     
     
     
     
    	}
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Memory test game program !

    i want those inputs.. to be used later again
    Do you know about ArrayLists or arrays? They are useful for saving input.

    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.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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 ?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Memory test game program !

    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.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Help with my memory concentration game (2D Array help)
    By lukeyry in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 18th, 2012, 08:33 AM
  2. Replies: 2
    Last Post: September 27th, 2012, 07:06 PM
  3. Memory Card Game JButtons Array
    By rlo10 in forum What's Wrong With My Code?
    Replies: 26
    Last Post: March 4th, 2012, 05:02 PM
  4. Problem with Memory Card Game
    By rlo10 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 18th, 2012, 10:09 PM
  5. HELP ME PLEASE MEMORY MANAGEMENT PROGRAM USING JAVA
    By lockwater in forum Java Theory & Questions
    Replies: 1
    Last Post: December 2nd, 2010, 08:30 AM

Tags for this Thread