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.

Page 1 of 2 12 LastLast
Results 1 to 25 of 26

Thread: Java Jeopardy Game, Please Help

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Jeopardy Game, Please Help

    I'm trying to make a jeopardy game based on java for my Computer Science Class, but i'm having problems with my program at the moment. To start, i am unsure of the proper grid layout, and i need some assistance in creating the assortment of J Buttons within the program itself. Below is a snippet of my program, please help me with fixing the errors, thank you very much.

     
    import java.util.Scanner;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
      public class DannysJeopardy2 extends JFrame implements ActionListener {
     
        int width = 800;
        int height = 800;
        int score;
        JLabel methods = new JLabel("Methods");
        JButton methods1 = new JButton("$100");
        JButton methods2 = new JButton ("$200");
        JButton methods3 = new JButton ("$300");
        JButton methods4 = new JButton("$500");
     
        JLabel strings = new JLabel("Strings");
        JButton strings1 = new JButton("$100");
        JButton strings2 = new JButton("$200");
        JButton strings3 = new JButton("$300");
        JButton strings4 = new JButton("$500");
     
        JLabel conditional = new JLabel("Conditional Control Structures");
        JButton conditional1 = new JButton("$100");
        JButton conditional2 = new JButton("$200");
        JButton conditional3 = new JButton("$300");
        JButton conditional4 = new JButton("$500");
     
        JLabel loops = new JLabel("Loops");
        JButton loops1 = new JButton("$100");
        JButton loops2 = new JButton("$200");
        JButton loops3 = new JButton("$300");
        JButton loops4 = new JButton("$500");
        JButton bRestart = new JButton("Restart");
     
        public DannysJeopardy2(){
            super("Jeopardy!");
            this.setVisible(true);
            this.setSize(width, height);
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);
     
            Container contentPane = getContentPane();
            bYoureinthis.setLocation(0, 0);
            bYoureinthis.setSize(200, 200);
            contentPane.add(bYoureinthis);
        }   
     
    public static void main (String[] args) {
     
        public void actions (Object source) {
        Object source;   
        int tScore;
        int score; 
          if (source == methods1)
          {   methods(); }
          if (source == strings1)
          {  strings();   }
          if (source == conditional1)
          {  conditional();  }
          if (source == loops1)
          {  loops();  }
     
          if (source == methods2)
          {   methods(); }
          if (source == strings2)
          {  strings();   }
          if (source == conditional2)
          {  conditional();  }
          if (source == loops2)
          {  loops();  }
     
          if (source == methods3)
          {   methods(); }
          if (source == strings3)
          {  strings();   }
          if (source == conditional3)
          {  conditional();  }
          if (source == loops3)
          {  loops();  }
     
          if (source == methods4)
          {   methods(); }
          if (source == strings4)
          {  strings();   }
          if (source == conditional4)
          {  conditional();  }
          if (source == loops4)
          {  loops();  }
     
             methods1.setEnabled(true);
             strings1.setEnabled(true);
             conditional1.setEnabled(true);
             loops1.setEnabled(true);
     
             methods2.setEnabled(true);
             strings2.setEnabled(true);
             conditional2.setEnabled(true);
             loops2.setEnabled(true);
     
             methods3.setEnabled(true);
             strings3.setEnabled(true);
             conditional3.setEnabled(true);
             loops3.setEnabled(true);
     
             methods4.setEnabled(true);
             strings4.setEnabled(true);
             conditional4.setEnabled(true);
             loops4.setEnabled(true);
             score = 0;
     
    tScore.setText(score + "");
          }  
       }


  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: Java Jeopardy Game, Please Help

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    Where does your code use any layout manager?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Java Jeopardy Game, Please Help

    Sorry, I'm sort of a beginner with java, and i didn't implement any layout manager. The problems with my program are the logic errors involved, i wondering if anyone here is able to help me. I'm having a great time making the program, but I'm sort of stumped with these errors. If anyone can help me with the program i would greatly appreciate it.

  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: Java Jeopardy Game, Please Help

    I'm sort of stumped with these errors.
    Please explain about the errors.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Jeopardy Game, Please Help

    The errors that i am having are surrounding the grid, i'm attempting to create a grid within the java program. I'm trying to link the Jbuttons to my questions within the jeopardy game but i'm not sure if i am doing it correctly. By using the JButtons, i want to prompt the user to select one of the choices in the categories, and by clicking on it, it will refer to the question similar to this one.
    /* The first group of questions within the $100 category*/
       public void methods1() {
          String guess = inputString("Methods are _________ designed to solve specific problem and are examples of object oriented problem.");
          if (guess.equalsIgnoreCase("tasks"))
          {
             score = score + 100;
             output("Right!");  
          }
          else
          {  
             score = score - 100;         
             output("Wrong, please try again" );
          }      
     
          methods1.setEnabled(false);
       }
    Also, the methods seem to be incorrect, while compiling the program and i'm not sure how to allow the user to input an answer after the question has appeared.

  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: Java Jeopardy Game, Please Help

    Can you post your current code. The code in post#1 is full of compiler errors.

    If you need help with any of the compiler errors, copy the full text of the error messages and paste them here.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Jeopardy Game, Please Help

    This is the current code, the questions bellow are only examples which i will be changing soon, but thanks for all the help your giving me, i really appreciate it.

    import java.util.Scanner;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
      public class DannysJeopardy2 extends JFrame implements ActionListener {
     
        int width = 800;
        int height = 800;
        int score;
        JLabel methods = new JLabel("Methods");
        JButton methods1 = new JButton("$100");
        JButton methods2 = new JButton ("$200");
        JButton methods3 = new JButton ("$300");
        JButton methods4 = new JButton("$500");
     
        JLabel strings = new JLabel("Strings");
        JButton strings1 = new JButton("$100");
        JButton strings2 = new JButton("$200");
        JButton strings3 = new JButton("$300");
        JButton strings4 = new JButton("$500");
     
        JLabel conditional = new JLabel("Conditional Control Structures");
        JButton conditional1 = new JButton("$100");
        JButton conditional2 = new JButton("$200");
        JButton conditional3 = new JButton("$300");
        JButton conditional4 = new JButton("$500");
     
        JLabel loops = new JLabel("Loops");
        JButton loops1 = new JButton("$100");
        JButton loops2 = new JButton("$200");
        JButton loops3 = new JButton("$300");
        JButton loops4 = new JButton("$500");
        JButton bRestart = new JButton("Restart");
     
        public DannysJeopardy2(){
            super("Jeopardy!");
            this.setVisible(true);
            this.setSize(width, height);
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);
     
            Container contentPane = getContentPane();
            bYoureinthis.setLocation(0, 0);
            bYoureinthis.setSize(200, 200);
            contentPane.add(bYoureinthis);
        }   
     
    public static void main (String[] args) {
     
        public void actions (Object source) {
        Object source;   
        int tScore;
        int score; 
          if (source == methods1)
          {   methods(); }
          if (source == strings1)
          {  strings();   }
          if (source == conditional1)
          {  conditional();  }
          if (source == loops1)
          {  loops();  }
     
          if (source == methods2)
          {   methods(); }
          if (source == strings2)
          {  strings();   }
          if (source == conditional2)
          {  conditional();  }
          if (source == loops2)
          {  loops();  }
     
          if (source == methods3)
          {   methods(); }
          if (source == strings3)
          {  strings();   }
          if (source == conditional3)
          {  conditional();  }
          if (source == loops3)
          {  loops();  }
     
          if (source == methods4)
          {   methods(); }
          if (source == strings4)
          {  strings();   }
          if (source == conditional4)
          {  conditional();  }
          if (source == loops4)
          {  loops();  }
     
             methods1.setEnabled(true);
             strings1.setEnabled(true);
             conditional1.setEnabled(true);
             loops1.setEnabled(true);
     
             methods2.setEnabled(true);
             strings2.setEnabled(true);
             conditional2.setEnabled(true);
             loops2.setEnabled(true);
     
             methods3.setEnabled(true);
             strings3.setEnabled(true);
             conditional3.setEnabled(true);
             loops3.setEnabled(true);
     
             methods4.setEnabled(true);
             strings4.setEnabled(true);
             conditional4.setEnabled(true);
             loops4.setEnabled(true);
             score = 0;
     
    tScore.setText(score + "");
          }  
       }
    /* The first group of questions within the $100 category*/
       public void methods1() {
          String guess = inputString("Methods are _________ designed to solve specific problem and are examples of object oriented problem.");
          if (guess.equalsIgnoreCase("tasks"))
          {
             score = score + 100;
             output("Right!");  
          }
          else
          {  
             score = score - 100;         
             output("Wrong, please try again" );
          }      
     
          methods1.setEnabled(false);
       }
     
          public void strings1()
       {
          String guess = inputString("Which String class method returns an integer value?");
          if (guess.equalsIgnoreCase("length()"))
          {
             score = score + 100;
             output("Right!");  
          }
          else
          {  
             score = score - 100;         
             output("Wrong, please try again" );
          }      
     
          strings1.setEnabled(false);
       }
     
          public void conditional1()
       {
          String guess = inputString("Relational opertors are used to form __________ expressions.");
          if (guess.equalsIgnoreCase("boolean"))
          {
             score = score + 100;
             output("Right!");  
          }
          else
          {  
             score = score - 100;         
             output("Wrong, please try again" );
          }      
     
          conditional1.setEnabled(false);
       }
     
          public void loops1()
       {
          String guess = inputString("Each execution of a loop is referred to as an _________");
          if (guess.equalsIgnoreCase("Iteration"))
          {
             score = score + 100;
             output("Right!");  
          }
          else
          {  
             score = score - 100;         
             output("Wrong, please try again" );
          }
             loops1.setEnabled(false);
     
     /* The second group of questions within the $200 category*/
     
          public void methods2() {
          String guess = inputString("Methods are _________ designed to solve specific problem and are examples of object oriented problem.");
          if (guess.equalsIgnoreCase("tasks"))
          {
             score = score + 200;
             output("Right!");  
          }
          else
          {  
             score = score - 200;         
             output("Wrong, please try again" );
          }      
     
          methods2.setEnabled(false);
       }
     
          public void strings2()
       {
          String guess = inputString("Which String class method returns an integer value?");
          if (guess.equalsIgnoreCase("length()"))
          {
             score = score + 200;
             output("Right!");  
          }
          else
          {  
             score = score - 200;         
             output("Wrong, please try again" );
          }      
     
          strings2.setEnabled(false);
       }
     
          public void conditional2()
       {
          String guess = inputString("Relational opertors are used to form __________ expressions.");
          if (guess.equalsIgnoreCase("boolean"))
          {
             score = score + 200;
             output("Right!");  
          }
          else
          {  
             score = score - 200;         
             output("Wrong, please try again" );
          }      
     
          conditional2.setEnabled(false);
       }
     
          public void loops2()
       {
          String guess = inputString("Each execution of a loop is referred to as an _________");
          if (guess.equalsIgnoreCase("Iteration"))
          {
             score = score + 200;
             output("Right!");  
          }
          else
          {  
             score = score - 200;         
             output("Wrong, please try again" );
          }
             loops2.setEnabled(false);
          } 
     
    /* The third group of questions within the $300 category*/
     
          public void methods3() {
          String guess = inputString("Methods are _________ designed to solve specific problem and are examples of object oriented problem.");
          if (guess.equalsIgnoreCase("tasks"))
          {
             score = score + 300;
             output("Right!");  
          }
          else
          {  
             score = score - 300;         
             output("Wrong, please try again" );
          }      
     
          methods3.setEnabled(false);
       }
     
          public void strings3()
       {
          String guess = inputString("Which String class method returns an integer value?");
          if (guess.equalsIgnoreCase("length()"))
          {
             score = score + 300;
             output("Right!");  
          }
          else
          {  
             score = score - 300;         
             output("Wrong, please try again" );
          }      
     
          strings3.setEnabled(false);
       }
     
          public void conditional3()
       {
          String guess = inputString("Relational opertors are used to form __________ expressions.");
          if (guess.equalsIgnoreCase("boolean"))
          {
             score = score + 300;
             output("Right!");  
          }
          else
          {  
             score = score - 300;         
             output("Wrong, please try again" );
          }      
     
          conditional3.setEnabled(false);
       }
     
          public void loops3()
       {
          String guess = inputString("Each execution of a loop is referred to as an _________");
          if (guess.equalsIgnoreCase("Iteration"))
          {
             score = score + 300;
             output("Right!");  
          }
          else
          {  
             score = score - 300;         
             output("Wrong, please try again" );
          }
             loops3.setEnabled(false);
          } 
     
     /* The fourth group of questions within the $500 category*/
     
          public void methods4() {
          String guess = inputString("Methods are _________ designed to solve specific problem and are examples of object oriented problem.");
          if (guess.equalsIgnoreCase("tasks"))
          {
             score = score + 500;
             output("Right!");  
          }
          else
          {  
             score = score - 500;         
             output("Wrong, please try again" );
          }      
     
          methods4.setEnabled(false);
       }
     
          public void strings4()
       {
          String guess = inputString("Which String class method returns an integer value?");
          if (guess.equalsIgnoreCase("length()"))
          {
             score = score + 500;
             output("Right!");  
          }
          else
          {  
             score = score - 500;         
             output("Wrong, please try again" );
          }      
     
          strings4.setEnabled(false);
       }
     
          public void conditional4()
       {
          String guess = inputString("Relational opertors are used to form __________ expressions.");
          if (guess.equalsIgnoreCase("boolean"))
          {
             score = score + 500;
             output("Right!");  
          }
          else
          {  
             score = score - 500;         
             output("Wrong, please try again" );
          }      
     
          conditional4.setEnabled(false);
       }
     
          public void loops4()
       {
          String guess = inputString("Each execution of a loop is refered to as an _________");
          if (guess.equalsIgnoreCase("Iteration"))
          {
             score = score + 500;
             output("Right!");  
          }
          else
          {  
             score = score - 500;         
             output("Wrong, please try again" );
          }
             loops4.setEnabled(false);
          }    
        }
    }


    51 errors found:
    File: F:\Computer Science\DannysJeopardy2.java [line: 7]
    Error: The type DannysJeopardy2 must implement the inherited abstract method java.awt.event.ActionListener.actionPerformed(java .awt.event.ActionEvent)
    File: F:\Computer Science\DannysJeopardy2.java [line: 44]
    Error: bYoureinthis cannot be resolved
    File: F:\Computer Science\DannysJeopardy2.java [line: 45]
    Error: bYoureinthis cannot be resolved
    File: F:\Computer Science\DannysJeopardy2.java [line: 46]
    Error: bYoureinthis cannot be resolved to a variable
    File: F:\Computer Science\DannysJeopardy2.java [line: 51]
    Error: Syntax error on token "(", ; expected
    File: F:\Computer Science\DannysJeopardy2.java [line: 51]
    Error: Syntax error on token ")", ; expected
    File: F:\Computer Science\DannysJeopardy2.java [line: 117]
    Error: The method inputString(java.lang.String) is undefined for the type DannysJeopardy2
    File: F:\Computer Science\DannysJeopardy2.java [line: 121]
    Error: The method output(java.lang.String) is undefined for the type DannysJeopardy2
    File: F:\Computer Science\DannysJeopardy2.java [line: 126]
    Error: The method output(java.lang.String) is undefined for the type DannysJeopardy2
    File: F:\Computer Science\DannysJeopardy2.java [line: 134]
    Error: The method inputString(java.lang.String) is undefined for the type DannysJeopardy2
    File: F:\Computer Science\DannysJeopardy2.java [line: 138]
    Error: The method output(java.lang.String) is undefined for the type DannysJeopardy2
    File: F:\Computer Science\DannysJeopardy2.java [line: 143]
    Error: The method output(java.lang.String) is undefined for the type DannysJeopardy2
    File: F:\Computer Science\DannysJeopardy2.java [line: 151]
    Error: The method inputString(java.lang.String) is undefined for the type DannysJeopardy2
    File: F:\Computer Science\DannysJeopardy2.java [line: 155]
    Error: The method output(java.lang.String) is undefined for the type DannysJeopardy2
    File: F:\Computer Science\DannysJeopardy2.java [line: 160]
    Error: The method output(java.lang.String) is undefined for the type DannysJeopardy2
    File: F:\Computer Science\DannysJeopardy2.java [line: 183]
    Error: Syntax error on token "void", @ expected
    File: F:\Computer Science\DannysJeopardy2.java [line: 183]
    Error: Syntax error on token "{", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 197]
    Error: Syntax error on token "}", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 199]
    Error: Syntax error on token "void", @ expected
    File: F:\Computer Science\DannysJeopardy2.java [line: 200]
    Error: Syntax error on token "{", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 214]
    Error: Syntax error on token "}", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 216]
    Error: Syntax error on token "void", @ expected
    File: F:\Computer Science\DannysJeopardy2.java [line: 217]
    Error: Syntax error on token "{", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 231]
    Error: Syntax error on token "}", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 233]
    Error: Syntax error on token "void", @ expected
    File: F:\Computer Science\DannysJeopardy2.java [line: 234]
    Error: Syntax error on token "{", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 247]
    Error: Syntax error on token "}", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 251]
    Error: Syntax error on token "void", @ expected
    File: F:\Computer Science\DannysJeopardy2.java [line: 251]
    Error: Syntax error on token "{", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 265]
    Error: Syntax error on token "}", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 267]
    Error: Syntax error on token "void", @ expected
    File: F:\Computer Science\DannysJeopardy2.java [line: 268]
    Error: Syntax error on token "{", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 282]
    Error: Syntax error on token "}", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 284]
    Error: Syntax error on token "void", @ expected
    File: F:\Computer Science\DannysJeopardy2.java [line: 285]
    Error: Syntax error on token "{", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 299]
    Error: Syntax error on token "}", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 301]
    Error: Syntax error on token "void", @ expected
    File: F:\Computer Science\DannysJeopardy2.java [line: 302]
    Error: Syntax error on token "{", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 315]
    Error: Syntax error on token "}", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 319]
    Error: Syntax error on token "void", @ expected
    File: F:\Computer Science\DannysJeopardy2.java [line: 319]
    Error: Syntax error on token "{", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 333]
    Error: Syntax error on token "}", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 335]
    Error: Syntax error on token "void", @ expected
    File: F:\Computer Science\DannysJeopardy2.java [line: 336]
    Error: Syntax error on token "{", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 350]
    Error: Syntax error on token "}", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 352]
    Error: Syntax error on token "void", @ expected
    File: F:\Computer Science\DannysJeopardy2.java [line: 353]
    Error: Syntax error on token "{", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 367]
    Error: Syntax error on token "}", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 369]
    Error: Syntax error on token "void", @ expected
    File: F:\Computer Science\DannysJeopardy2.java [line: 370]
    Error: Syntax error on token "{", delete this token
    File: F:\Computer Science\DannysJeopardy2.java [line: 383]
    Error: Syntax error on token "}", delete this token

  8. #8
    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: Java Jeopardy Game, Please Help

    cannot be resolved
    These errors are because the compiler can not find the definition for the variable. Make sure you have defined the variable whose name is in the error message.
    method inputString(java.lang.String) is undefined for the type
    The compiler can not find the method: inputString(String). Where is that method defined?
    The same for other errors: "can not find the method". Add a definition for the method that is not found.

    Hint: Compile more often. Don't type in too many lines before doing a compile. Correct the errors found before typing in any more code.

    Suggestion: Delete most of the code in the program where the errors are and start over. Type in a few lines, compile the program, fix the errors before typing in more lines of code.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Dec 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Jeopardy Game, Please Help

    i know i have a lot of errors, but can you help me with any of the compiler errors, its sort overwhelming. I'm not sure how to solve the deleting token errors and the variables, i'm sort of a beginner with java

  10. #10
    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: Java Jeopardy Game, Please Help

    can you help me with any of the compiler errors
    Did you make the fixes I described in post#8? There were a lot of things that needed to be defined in the code.


    Have you tried my suggestion of deleting most of the statements and starting over?

    Type in a small start for the program, compile it, fix the errors and then type in some more, compile it, fix the errors and so on. Never type in more than 5-10 statements before compiling it and fixing the errors.

    51 errors is too many to work with.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Dec 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Jeopardy Game, Please Help

    due to time restraints, i'm not sure that i can start over, but i'm trying to fix the program errors. But i was just wondering if i'm on the right tract. I need some help with defining some of the variables and solving the deleting tokens problems. I've been working on it, but i can't seem to solve it.

    What i'm worried about is creating the grid and allowing the user to utilize the J Buttons and input an answer for the questions, but i'm not sure if i am doing it right
      if (source == methods1)
          {   methods(); }
          if (source == strings1)
          {  strings();   }
          if (source == conditional1)
          {  conditional();  }
          if (source == loops1)
          {  loops();  }
     
             methods1.setEnabled(true);
             strings1.setEnabled(true);
             conditional1.setEnabled(true);
             loops1.setEnabled(true);
    I want to be able to prompt the user to select a choice (e.g loops1) and then the question appears for the person to answer it. Any help would be useful.

  12. #12
    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: Java Jeopardy Game, Please Help

    You need to resolve the existing compiler errors before adding any more code.

    Can only one of the if statements in the list of if statements be true at a time?
    If so, you should use if/else if statements that show that relationship between the if statements.

    The formatting of the code does not follow standards. There should NOT be any other code on the same line with the ending bracket:} or following a beginning bracket: {
    {  conditional();  }  //<<<<<<<<<< wrong
    vs
    {  
       conditional();     //  This way
    }

    need some help with defining some of the variables
    Can you explain what problems you are having defining any of the variables?

    solving the deleting tokens problems.
    What is the "deleting tokens problem"?

    to prompt the user to select a choice
    Print a message and read the response. The Scanner class has easy to use methods for reading a user's response from the console.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Dec 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Jeopardy Game, Please Help

    I'm currently using this as an example Jeopardy.java , my goal is to have it to work the same way. I meant to say that i needed to define the methods and for some reason, there are errors requiring me to delete tokens such as } and void.

    File: F:\Computer Science\DannysJeopardy2.java [line: 183]
    Error: Syntax error on token "void", @ expected
    File: F:\Computer Science\DannysJeopardy2.java [line: 183]
    Error: Syntax error on token "{", delete this token

  14. #14
    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: Java Jeopardy Game, Please Help

    Can you post the lines of code around line 183 and put a comment on line 183 to identify it.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Dec 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Jeopardy Game, Please Help

    I'm sorry i'm spending a lot of your time Norm, but do you understand the project itself. I'm making a Jeopardy program as a project. By using if else statements i want to be able to allow the user to select one of the 16 questions and if the answer is correct, the total score will increase by a fixed amount, if the answer is incorrect, the total score will be deducted by a fixed amount. Using the example, i'm not sure whether or not that is the right method to use.

    /* The second group of questions within the $200 category*/
     
          public void methods2() {  /* This is line 183, where the error is occuring */
          String guess = inputString("Methods are _________ designed to solve specific problem and are examples of object oriented problem.");
          if (guess.equalsIgnoreCase("tasks"))
          {
             score = score + 200;
             output("Right!");  
          }
          else
          {  
             score = score - 200;         
             output("Wrong, please try again" );
          }      
     
          methods2.setEnabled(false);
       }

  16. #16
    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: Java Jeopardy Game, Please Help

    What are the lines before line 183?

    Check that all the {}s are properly paired: Each { needs a }
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Dec 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Jeopardy Game, Please Help

    /* The first group of questions within the $100 category*/
       public void methods1() {
          String guess = inputString("Methods are _________ designed to solve specific problem and are examples of object oriented problem.");
          if (guess.equalsIgnoreCase("tasks"))
          {
             score = score + 100;
             output("Right!");  
          }
          else
          {  
             score = score - 100;         
             output("Wrong, please try again" );
          }      
     
          methods1.setEnabled(false);
       }
     
          public void strings1()
       {
          String guess = inputString("Which String class method returns an integer value?");
          if (guess.equalsIgnoreCase("length()"))
          {
             score = score + 100;
             output("Right!");  
          }
          else
          {  
             score = score - 100;         
             output("Wrong, please try again" );
          }      
     
          strings1.setEnabled(false);
       }
     
          public void conditional1()
       {
          String guess = inputString("Relational opertors are used to form __________ expressions.");
          if (guess.equalsIgnoreCase("boolean"))
          {
             score = score + 100;
             output("Right!");  
          }
          else
          {  
             score = score - 100;         
             output("Wrong, please try again" );
          }      
     
          conditional1.setEnabled(false);
       }
     
          public void loops1()
       {
          String guess = inputString("Each execution of a loop is referred to as an _________");
          if (guess.equalsIgnoreCase("Iteration"))
          {
             score = score + 100;
             output("Right!");  
          }
          else
          {  
             score = score - 100;         
             output("Wrong, please try again" );
          }
             loops1.setEnabled(false);

  18. #18
    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: Java Jeopardy Game, Please Help

    Did you check that all the {}s were properly paired?

    The code you just posted doesn't show which line is line 183.
    I expected to see:
    some lines
    line 183 <<<<<<<<<< in the middle
    some lines
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Junior Member
    Join Date
    Dec 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Jeopardy Game, Please Help

    Here is the code, but this is probably the least of my worries, i'm guessing that the errors will be surrounding the methods. The first method appears to be the one that needs to be fixed, where the actionlistener is incorrect ( public class DannysJeopardy2 extends JFrame implements ActionListener {), also, the method inputstring is undefined
    /* The first group of questions within the $100 category*/
       public void methods1() {
          String guess = inputString("Methods are _________ designed to solve specific problem and are examples of object oriented problem.");
          if (guess.equalsIgnoreCase("tasks"))
          {
             score = score + 100;
             output("Right!");  
          }
          else
          {  
             score = score - 100;         
             output("Wrong, please try again" );
          }      
     
          methods1.setEnabled(false);
       }
     
          public void strings1()
       {
          String guess = inputString("Which String class method returns an integer value?");
          if (guess.equalsIgnoreCase("length()"))
          {
             score = score + 100;
             output("Right!");  
          }
          else
          {  
             score = score - 100;         
             output("Wrong, please try again" );
          }      
     
          strings1.setEnabled(false);
       }
     
          public void conditional1()
       {
          String guess = inputString("Relational opertors are used to form __________ expressions.");
          if (guess.equalsIgnoreCase("boolean"))
          {
             score = score + 100;
             output("Right!");  
          }
          else
          {  
             score = score - 100;         
             output("Wrong, please try again" );
          }      
     
          conditional1.setEnabled(false);
       }
     
          public void loops1()
       {
          String guess = inputString("Each execution of a loop is referred to as an _________");
          if (guess.equalsIgnoreCase("Iteration"))
          {
             score = score + 100;
             output("Right!");  
          }
          else
          {  
             score = score - 100;         
             output("Wrong, please try again" );
          }
             loops1.setEnabled(false);
     
     /* The second group of questions within the $200 category*/
     
          public void methods2() { //****************This is line 183 where the error is occurring*/
          String guess = inputString("Methods are _________ designed to solve specific problem and are examples of object oriented problem.");
          if (guess.equalsIgnoreCase("tasks"))
          {
             score = score + 200;
             output("Right!");  
          }
          else
          {  
             score = score - 200;         
             output("Wrong, please try again" );
          }      
     
          methods2.setEnabled(false);
       }
     
          public void strings2()
       {
          String guess = inputString("Which String class method returns an integer value?");
          if (guess.equalsIgnoreCase("length()"))
          {
             score = score + 200;
             output("Right!");  
          }
          else
          {  
             score = score - 200;         
             output("Wrong, please try again" );
          }      
     
          strings2.setEnabled(false);
       }
     
          public void conditional2()
       {
          String guess = inputString("Relational opertors are used to form __________ expressions.");
          if (guess.equalsIgnoreCase("boolean"))
          {
             score = score + 200;
             output("Right!");  
          }
          else
          {  
             score = score - 200;         
             output("Wrong, please try again" );
          }      
     
          conditional2.setEnabled(false);
       }
     
          public void loops2()
       {
          String guess = inputString("Each execution of a loop is referred to as an _________");
          if (guess.equalsIgnoreCase("Iteration"))
          {
             score = score + 200;
             output("Right!");  
          }
          else
          {  
             score = score - 200;         
             output("Wrong, please try again" );
          }
             loops2.setEnabled(false);
          }

  20. #20
    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: Java Jeopardy Game, Please Help

    Did you check that the {}s are properly paired?

    In the posted code: Where is line 183? I don't see any comments like: //******* THIS IS LINE 183 <<<<<<<<<<<<


    the method inputstring is undefined
    Write a definition for the method so the compiler can find it. Just a minimal method so the compiler is happy.
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Junior Member
    Join Date
    Dec 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Jeopardy Game, Please Help

    I have updated post #19 and identified where the error is present. That single error is repeated throughout the second portion of the program, which can be fixed, but i'm not sure of how to write a definition for the method compiler. If it is possible can you edit the code yourself and adjust some of the minor errors within the program and double check the {} pairings. I fixed some of the formatting errors already.

  22. #22
    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: Java Jeopardy Game, Please Help

    Did you check that all the {}s were matched?

    What errors are you getting now?

    how to write a definition for the method
    Don't worry about the inside of the method for now. Just write the first line and the last line to define the method. Fill-in the logic later.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Junior Member
    Join Date
    Dec 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Jeopardy Game, Please Help

    Thanks for the advice Norm, i found out that to fix the tokens problem, i checked the {}, one of the missing curly brackets caused all the errors. I managed to reduce the errors to only 5 now , but i'm not sure how to solve the fix the action listener problem. Also, i am unable to display the total score within the program as shown bellow /*** error with tscore. In addition, the guess, which is the user input is oddly the incorrect return type. If it is possible, can you physically edit the text yourself to adjust any of the errors.

    import java.util.Scanner;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
      public class DannysJeopardy2 extends JFrame implements ActionListener { /*Action listener problem*/
     
        int width = 800;
        int height = 800;
        int score;
        JLabel methods = new JLabel("Methods");
        JButton methods1 = new JButton("$100");
        JButton methods2 = new JButton ("$200");
        JButton methods3 = new JButton ("$300");
        JButton methods4 = new JButton("$500");
     
        JLabel strings = new JLabel("Strings");
        JButton strings1 = new JButton("$100");
        JButton strings2 = new JButton("$200");
        JButton strings3 = new JButton("$300");
        JButton strings4 = new JButton("$500");
     
        JLabel conditional = new JLabel("Conditional Control Structures");
        JButton conditional1 = new JButton("$100");
        JButton conditional2 = new JButton("$200");
        JButton conditional3 = new JButton("$300");
        JButton conditional4 = new JButton("$500");
     
        JLabel loops = new JLabel("Loops");
        JButton loops1 = new JButton("$100");
        JButton loops2 = new JButton("$200");
        JButton loops3 = new JButton("$300");
        JButton loops4 = new JButton("$500");
        JButton bRestart = new JButton("Restart");
     
        public DannysJeopardy2(){
            super("Jeopardy!");
            this.setVisible(true);
            this.setSize(width, height);
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        }   
     
    public static void main (String[] args) {
     
        public void actions (Object source) {  
        int tScore;
        int score;
        String guess;
     
     
          if (source == methods1)
          {   methods1(); }
          if (source == strings1)
          {  strings1();   }
          if (source == conditional1)
          {  conditional1();  }
          if (source == loops1)
          {  loops1();  }
     
          if (source == methods2)
          {   methods2(); }
          if (source == strings2)
          {  strings2();   }
          if (source == conditional2)
          {  conditional2();  }
          if (source == loops2)
          {  loops2();  }
     
          if (source == methods3)
          {   methods3(); }
          if (source == strings3)
          {  strings3();   }
          if (source == conditional3)
          {  conditional3();  }
          if (source == loops3)
          {  loops3();  }
     
          if (source == methods4)
          {   methods4(); }
          if (source == strings4)
          {  strings4();   }
          if (source == conditional4)
          {  conditional4();  }
          if (source == loops4)
          {  loops4();  }
     
             methods1.setEnabled(true);
             strings1.setEnabled(true);
             conditional1.setEnabled(true);
             loops1.setEnabled(true);
     
             methods2.setEnabled(true);
             strings2.setEnabled(true);
             conditional2.setEnabled(true);
             loops2.setEnabled(true);
     
             methods3.setEnabled(true);
             strings3.setEnabled(true);
             conditional3.setEnabled(true);
             loops3.setEnabled(true);
     
             methods4.setEnabled(true);
             strings4.setEnabled(true);
             conditional4.setEnabled(true);
             loops4.setEnabled(true);
             score = 0;
     
    tScore.setText(score + ""); /**** TScore error, the score itself is unable to be displayed*/
          }  
     
        DannysJeopardy2 myWorld = new DannysJeopardy2();
     
        public void output(String s){
            JFrame rw = new JFrame("Are you right or wrong?");
            rw.setVisible(true);
            rw.setSize(200, 100);
            rw.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            rw.setAlwaysOnTop(true);
            JButton brw = new JButton(s);
            rw.getContentPane().add(brw);
            try
            {
                Thread.sleep(1000);
            }
            catch(Exception e){};
            rw.dispose();
        }
     
     
        public String inputString(String quest){
            JFrame what = new JFrame("What is your Guess?");
            what.setVisible(true);
            what.setSize(400, 200);
            what.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            what.setAlwaysOnTop(true);
            JTextField question = new JTextField(quest);
            JTextField guess = new JTextField(50);
            Container x = what.getContentPane();
            x.setLayout(new FlowLayout());
            x.add(question);
            x.add(guess);
            JButton enter = new JButton("Enter");
            x.add(enter);
     
            enter.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){   /****Return type is incorrect*/
                    return guess.getText(); /***Return type is incorrect*/     
                }
            });
     
        }

  24. #24
    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: Java Jeopardy Game, Please Help

    how to solve the fix the action listener problem.
    See the tutorial on how to write a listener:
    How to Write an Action Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)

    i am unable to display the total score
    You need to fix all the compiler errors before trying to execute the code.

    If there are errors you are having problems with, copy the full text of the error messages and post them.
    If you don't understand my answer, don't ignore it, ask a question.

  25. #25
    Junior Member
    Join Date
    Dec 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Jeopardy Game, Please Help

    I've listed all of the errors in the program and identified where they are. I've been working on this all morning, but i can't figure our how to fix the remaining errors. Can you please help me to find a solution to finish the program, also, can you add edit or improve anything within the program itself.

    import java.util.Scanner;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
      public class DannysJeopardy2 extends JFrame implements ActionListener { /***Line 7 Error*/ 
        int width = 800;
        int height = 800;
        int score;
        JLabel methods = new JLabel("Methods");
        JButton methods1 = new JButton("$100");
        JButton methods2 = new JButton ("$200");
        JButton methods3 = new JButton ("$300");
        JButton methods4 = new JButton("$500");
     
        JLabel strings = new JLabel("Strings");
        JButton strings1 = new JButton("$100");
        JButton strings2 = new JButton("$200");
        JButton strings3 = new JButton("$300");
        JButton strings4 = new JButton("$500");
     
        JLabel conditional = new JLabel("Conditional Control Structures");
        JButton conditional1 = new JButton("$100");
        JButton conditional2 = new JButton("$200");
        JButton conditional3 = new JButton("$300");
        JButton conditional4 = new JButton("$500");
     
        JLabel loops = new JLabel("Loops");
        JButton loops1 = new JButton("$100");
        JButton loops2 = new JButton("$200");
        JButton loops3 = new JButton("$300");
        JButton loops4 = new JButton("$500");
        JButton bRestart = new JButton("Restart");
     
        public DannysJeopardy2(){
            super("Jeopardy!");
            this.setVisible(true);
            this.setSize(width, height);
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        }   
     
    public static void main (String[] args) { /***Line 44 error*/
     
        public void actions (Object source) {  
        int tScore;
        int score;
        String guess;
     
     
          if (source == methods1)
          {   methods1(); }
          if (source == strings1)
          {  strings1();   }
          if (source == conditional1)
          {  conditional1();  }
          if (source == loops1)
          {  loops1();  }
     
          if (source == methods2)
          {   methods2(); }
          if (source == strings2)
          {  strings2();   }
          if (source == conditional2)
          {  conditional2();  }
          if (source == loops2)
          {  loops2();  }
     
          if (source == methods3)
          {   methods3(); }
          if (source == strings3)
          {  strings3();   }
          if (source == conditional3)
          {  conditional3();  }
          if (source == loops3)
          {  loops3();  }
     
          if (source == methods4)
          {   methods4(); }
          if (source == strings4)
          {  strings4();   }
          if (source == conditional4)
          {  conditional4();  }
          if (source == loops4)
          {  loops4();  }
     
             methods1.setEnabled(true);
             strings1.setEnabled(true);
             conditional1.setEnabled(true);
             loops1.setEnabled(true);
     
             methods2.setEnabled(true);
             strings2.setEnabled(true);
             conditional2.setEnabled(true);
             loops2.setEnabled(true);
     
             methods3.setEnabled(true);
             strings3.setEnabled(true);
             conditional3.setEnabled(true);
             loops3.setEnabled(true);
     
             methods4.setEnabled(true);
             strings4.setEnabled(true);
             conditional4.setEnabled(true);
             loops4.setEnabled(true);
             score = 0;
     
    tScore.setText(score + "");
          }  
     
        DannysJeopardy2 myWorld = new DannysJeopardy2();
     
        public void output(String s){
            JFrame rw = new JFrame("Are you right or wrong?");
            rw.setVisible(true);
            rw.setSize(200, 100);
            rw.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            rw.setAlwaysOnTop(true);
            JButton brw = new JButton(s);
            rw.getContentPane().add(brw);
            try
            {
                Thread.sleep(1000);
            }
            catch(Exception e){};
            rw.dispose();
        }
     
     
        public String inputString(String quest){
            JFrame what = new JFrame("What is your Guess?");
            what.setVisible(true);
            what.setSize(400, 200);
            what.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            what.setAlwaysOnTop(true);
            JTextField question = new JTextField(quest);
            JTextField guess = new JTextField(50);
            Container x = what.getContentPane();
            x.setLayout(new FlowLayout());
            x.add(question);
            x.add(guess);
            JButton enter = new JButton("Enter");
            x.add(enter);
     
            enter.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    return guess.getText(); /*** Line 148 Error*/
                }
            });
     
        }

    5 errors found:
    File: F:\Computer Science\DannysJeopardy2.java [line: 7]
    Error: The type DannysJeopardy2 must implement the inherited abstract method java.awt.event.ActionListener.actionPerformed(java .awt.event.ActionEvent)
    File: F:\Computer Science\DannysJeopardy2.java [line: 44]
    Error: Syntax error, insert "}" to complete MethodBody
    File: F:\Computer Science\DannysJeopardy2.java [line: 109]
    Error: Cannot invoke setText(java.lang.String) on the primitive type int
    File: F:\Computer Science\DannysJeopardy2.java [line: 148]
    Error: Void methods cannot return a value
    File: F:\Computer Science\DannysJeopardy2.java [line: 148]
    Error: Cannot refer to a non-final variable guess inside an inner class defined in a different method

Page 1 of 2 12 LastLast

Similar Threads

  1. 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
  2. [SOLVED] Java Game
    By aman_chauhan in forum What's Wrong With My Code?
    Replies: 0
    Last Post: July 3rd, 2012, 04:53 AM
  3. 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
  4. 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
  5. Need help for my java game
    By blunderblitz in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 27th, 2010, 05:32 AM