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 3 of 3

Thread: Jeopardy Game Help

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Jeopardy Game Help

    Hi I'm making a simple jeopardy program for my computer science class but I can't figure out why the input never matches the answer given.
    I still need to implement a score system but I believe the problem is in the "questions" method.




    public class CulminatingJeopardy2 {
      static String[][] questions = //Here is the list of questions used for the jeopardy game 
      { 
        {"He became Famous through youtube and was the artist who sang the song “baby”",
          "I’ll Make Man Out of You was a song in which 1998 Disney animation?",
          "Who is the most Famous White Rapper, also known as Slim Shady?",
          "Who is the Artist of these songs? Love story, you belong with me.",
          "Famous Canadian Rapper who “Started from the Bottom” ",},
        {"We live on this planet ",
          "Which planet is often referred to as “the red planet”? ",
          "Which planet is the farthest from the sun? ",
          "Which planet has a great red spot? ",
          "Which planet has the most rings? "},
        {"A way of virtually sending letters back and forth through cyberspace.",
          "On this popular website YOU can upload and watch videos. ",
          "On what popular program do we use to write documents? ",
          "You should never give this to strangers in chat rooms.",
          "In what year was the internet created? "},
        {"The main characters in this book are Opal and her dog ",
          "In this series, a group of four crime solving children live in a part of a train",
          "The narrator in this book frequently speaks about saving the children from adulthood ", 
          "In this novel, Scout and her brother Jem live in the fictional town of Maycomb. ",
          "One of Dr. Suess’s classics, this book involves a cartoon feline who terrorises when the parents are out "},
        {"Who is the current president?",
          "Who was the first president?",
          "Who was the president during the Civil War?",
          "Which president was involved in the Watergate Scandal?",
          "Which president was so large that he frequently got stuck in his bathtub?"},
        {"What sport consists of paddles, a smallball, and a table with a net?",
          "An arcade game consisting of a yellow character and ghosts in a maze.",
          "Athlete who won 8 medals in the olympics for swimming","Kobe Bryant is in which nba team?", 
          "What sport is Tiger Woods known for?"}};
      static String[][] answers = // Here is the list of answers for the jeopardy game
      {{"JUSTIN BIEBER", "MULAN", "EMINEM", "TAYLOR SWIFT", "DRAKE"},
        {"EARTH", "MARS", "PLUTO", "JUPITER", "SATURN"},
        {"E-MAIL","YOUTUBE", "MICROSOFT WORD", "PERSONAL INFORMATION", "1969"},
        {"WINN DIXIE", "BOX CAR CHILDREN", "CATCHER AND THE RYE", "TO KILL A MOCKINGBIRD", "CAT IN THE HAT"},
        {"BARACK OBAMA","GEORGE WASHINGTON","ABRAHAM LINCOLN","RICHARD NIXON", "WILLIAM TAFT"},
        {"TABLE TENNIS","PACMAN","MICHAEL PHELPS", "LAKERS","GOLF"}};
      static int[][] points = {{100,200,300,400,500},{100,200,300,400,500},{100,200,300,400,500},{100,200,300,400,500},{100,200,300,400,500},{100,200,300,400,500}};
      static int score = 0;  
      static boolean[][] state = {{false,false,false,false,false},{false,false,false,false,false},{false,false,false,false,false},{false,false,false,false,false},{false,false,false,false,false},{false,false,false,false,false}};
     
     
     
     
     
     
     
      public static void rungame ()
     
     
      {
        int choice1,choice2;
     
        System.out.println("     ");
        while(true)
        {
          System.out.println("Please select your category: [1] Music, [2] Space [3] Internet, [4] Name that book, [5] Presidents, [6] Games and Hobbies");
          choice1 = In.getInt();
          if(choice1 < 1 || choice1 > 6)
          {
            System.out.println("Not a valid category, please pick again");
            rungame(); }
          else
          {
            System.out.println("Please select your value: [1] $100, [2] $200, [3] $300, [4] $400, [5] $500" ); 
            choice2 = In.getInt();
     
            if(choice2 < 1 || choice2 > 5)
            {
              System.out.println("Not a valid value, please pick again") ; 
              rungame();
            }
            else
            {
              if (!state[choice1-1][choice2-1])
                questions(choice1,choice2);    
              else
     
                System.out.println("This category has already been selected, please pick again"); 
            }
          }
        }
      } 
     
     
     
     
     
     
     
      public static void questions(int choice1,int choice2)
      { 
        System.out.println(questions[choice1-1][choice2-1]);
        String answer = In.getString(); 
        if (answer.toUpperCase() == answers[choice1-1][choice2-1]){
          System.out.println("Congrats, you are correct!"); 
          score = score + points[choice1-1][choice2-1];
          System.out.println(score); 
        }
        else
          System.out.println("Sorry, you got the wrong answer"); 
        state[choice1-1][choice2-1] = true;
        score = score - points[choice1-1][choice2-1];
     
      }
     
     
      public static void startup ()
      {
        System.out.println("Welcome to Jeopardy!"); 
        System.out.println("Rules [1]");
        System.out.println("Start Game [2]");
        System.out.println("Quit [3]");
        System.out.println(" ");
        System.out.println(" Press [1] , [2] , or [3]"); 
        int x = In.getInt(); 
     
        if (x == 1)
        {
          System.out.println("These are the rules of the game: When prompted you will enter your category");
          System.out.println("number which is the column number(1,2,3,4,5,6) followed by the row number(1,2,3,4,5)");
          System.out.println("You will answer the question and press enter accordingly ");
          System.out.println("Go back to home screen? [1] = yes [anything else] = no"); 
          int y = In.getInt(); 
          if ( y == 1)
          {
            startup();
          }
          else
          {
            System.exit(0);
          }
        }
        else if (x == 2)
        {
     
          rungame();
        }
        else
        {
          System.exit(0);
        }
      }
     
      public static void main(String[] args) 
      {
        startup();
      }
    }


  2. #2
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Jeopardy Game Help

    Please keep in mind that when comparing strings you need to use the "equals" method instead of the "==" or "!=" operators.
    This might not be the only problem in your code but the first I saw when quickly looking over it.

  3. The Following 2 Users Say Thank You to Cornix For This Useful Post:

    CNHhobbes (May 28th, 2014), GregBrannon (May 29th, 2014)

  4. #3
    Junior Member
    Join Date
    May 2014
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Jeopardy Game Help

    Well that did the job, thank you

Similar Threads

  1. Replies: 3
    Last Post: March 1st, 2013, 11:01 PM
  2. Java Jeopardy Game, Please Help
    By luckyazn in forum What's Wrong With My Code?
    Replies: 25
    Last Post: December 25th, 2012, 05:28 PM
  3. Help with Snake Game Java Code: It's Impossible to Lose the Game
    By haruspex_icis in forum What's Wrong With My Code?
    Replies: 20
    Last Post: December 17th, 2012, 12:21 PM
  4. Simple game that requires me to load game settings from a file
    By 14fenix in forum Java Theory & Questions
    Replies: 5
    Last Post: December 1st, 2011, 09:21 PM
  5. Trying to make Jeopardy Game
    By wbroman in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 8th, 2010, 06:40 AM

Tags for this Thread