Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Norm

Thread: Why is my method undefined?

  1. #1
    EscSequenceAlpha is offline Senior Member
    Join Date
    Apr 2012
    Posts
    115
    Rep Power
    0

    Default Why is my method undefined?

    Ok guys, so this is the first time I departed from my ex. book, the task was to have an application that is just a multi-choice quiz... well, that didnt seem like any work because surely thats just a few if statements strung together so I decided to venture further and make an application that allows the user to make the quiz first.

    I ran into problems as amatures do... at one stage I realised I couldnt return my question objects because you can only return one thing from a method, so I encapsulated it into a quiz class.

    anyway heres my code

    Java Code:
    package chapter_v;
    
    import java.util.Scanner;
    
    public class GlobalWarningFactsQuiz_5_30 
    {
    	static Scanner input = new Scanner(System.in);
    	
    	public static Question_5_30 createQuestion()
    	{
    		System.out.println("What will be the question?");
    		String question = input.nextLine();
    		System.out.println("What will be multiple choice answer 1 of 4?");
    		String answer1 = input.nextLine();
    		System.out.println("What will be multiple choice answer 2 of 4?");
    		String answer2 = input.nextLine();
    		System.out.println("What will be multiple choice answer 3 of 4?");
    		String answer3 = input.nextLine();
    		System.out.println("What will be multiple choice answer 4 of 4?");
    		String answer4 = input.nextLine();
    		System.out.println("What is the correct answer? (1-4)");
    		int correctAnswer = input.nextInt();
    		
    		Question_5_30 completeQuestion = new Question_5_30(question, answer1, answer2, answer3, 
    				answer4, correctAnswer);
    		
    		return completeQuestion;
    	}
    	
    	public static Quiz_5_30 createQuiz()
    	{
    		System.out.println("Question1");
    		Question_5_30 q1 = createQuestion();
    		System.out.println("Question2");
    		Question_5_30 q2 = createQuestion();
    		System.out.println("Question3");;
    		Question_5_30 q3 = createQuestion();
    		System.out.println("Question4");
    		Question_5_30 q4 = createQuestion();
    		
    		Quiz_5_30 quiz = new Quiz_5_30(q1, q2, q3, q4);
    		
    		return quiz;
    	}
    	
    	public static void takeQuiz(Quiz_5_30 quiz)
    	{
    		int answer;
    		
    		System.out.println("Question1");
    		System.out.println(quiz.q1.getQuestion());
    		answer = input.nextInt();
    		if (answer == quiz.q1.getCorrectAnswer())               ---------------------error
    		{
    			
    		}
    		
    	}
    	
    	public static void main(String[] args)
    	{
    		System.out.println("Welcome to quizMaster!");
    				
    		Quiz_5_30 quiz = createQuiz();
    		takeQuiz(quiz);
    		
    	}
    }
    the quiz class is composed of 4 question objects
    the question class has the question, 4 possible answers and the correct answer

    when I get to the position marked error above I get
    The method takeQuiz() is undefined for the type GlobalWarningFactsQuiz_5_30

    what does this mean? I'm sure I followed the logic and I've passed the objects around correctly

    Also I've just realised it would make a lot more sense if the create question/quiz methods were written in their classes wouldnt it?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,901
    Rep Power
    25

    Default Re: Why is my method undefined?

    method takeQuiz() is undefined for the type GlobalWarningFactsQuiz_5_30
    what does this mean
    It means that the compiler can not find a definition for that method in that type/class.

    Please post the full text of the error message.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    EscSequenceAlpha is offline Senior Member
    Join Date
    Apr 2012
    Posts
    115
    Rep Power
    0

    Default Re: Why is my method undefined?

    I didnt execute it, it was just a red line and it said that and I didnt know why because the method clearly existed.

    but get this, I havent changed it at all and now the error has disappeared... what gives? I thought those squiggly lines were current but somehow while I left eclipse on for a few hours and come back it has re-evaluated it and no error.

    thats not very good error checking now is it, bad eclipse... how to avoid this?

    also does someone have an idiots guide to common errors and what they mean so I can better understand when something goes wrong. this is a good thing to have actually, someone must of made this on the internet somewhere

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,901
    Rep Power
    25

    Default Re: Why is my method undefined?

    I don't use an IDE and can't help you with it.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    EscSequenceAlpha is offline Senior Member
    Join Date
    Apr 2012
    Posts
    115
    Rep Power
    0

    Default Re: Why is my method undefined?

    I have another question.... perphapes more about practices. you know how after you do ScannerInstance.nextInt( )and then you want to capture a string do you do 2 * .nextLine() or do you create another scanner instance for strings to avoid that?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,901
    Rep Power
    25

    Default Re: Why is my method undefined?

    Write a small test program to read in something and print it out to see what happens. Try different combinations of the next ... methods to see what happens.
    EscSequenceAlpha likes this.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 7
    Last Post: 03-29-2012, 10:26 AM
  2. Replies: 3
    Last Post: 11-18-2011, 09:15 AM
  3. Replies: 10
    Last Post: 12-07-2010, 01:29 PM
  4. Replies: 2
    Last Post: 05-08-2010, 12:02 AM
  5. Replies: 0
    Last Post: 05-27-2009, 05:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •