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 33

Thread: missing return statement need help!!

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    15
    My Mood
    Confused
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default missing return statement need help!!

     
    /**
     * Write a description of class state here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    import java.util.*;
    import java.io.*;
    import java.util.Scanner;
    public class state
    {
    public static Void main(String[]args) throws FileNotFoundException
    {
     Scanner input = new Scanner (System.in);
     
     String s =" ";
     String[] data, category, option,option2,option3,option4;
     data =new String [50];
     category = new String[50];
     option = new String [50];
     option2 = new String [50];
     option3 = new String [50];
     option4 = new String [50];
     
     
     int [] choice, answer;
     choice = new int[50];
     answer = new int[50];
     
     
    System.out.printf(" Welcome to Quiz Creator",s);
    System.out.printf("What to do?",s);
    System.out.printf("1]Specify number of question you want to do");
    System.out.printf("2]Enter the question CATEGORY");
    System.out.printf("3]Enter the QUESTION for each category");
    System.out.printf("4]Enter the OPTION for each question");
    System.out.printf("5]Provide the ANSWER for each question");
    System.out.printf("6]Then your QUIZ GAME is ready to be play by your friend");
    System.out.printf("Press any key to start the game..");
    System.out.println();
    input.nextLine();
     
     
           System.out.println("How many question you want to create:");
           choice[1]=input.nextInt();
           System.out.println();
           System.out.print('\u000C');
           input.nextLine();
           System.out.println("Please enter your question CATEGORY");
     
           for (int a=0; a<choice[1];a++){
               System.out.print(choice[2]+1+"]  ");
               data[a]=input.nextLine();
               choice[2]=choice [2] + 1;
            }
            System.out.print('\u000C');
            System.out.println();
            System.out.println("Please enter your Question");
     
            for (int  b=0; b<choice[1];b++){
     
                System.out.println();
                System.out.println(" Category: " + data[b]);
                System.out.printf(choice[3] + 1 +" ] ");
                category[b]=input.nextLine();
                choice[3]=choice[3]+ 1;
            }
            System.out.print('\u000C');
            System.out.println();
            System.out.println("Please enter your question option ");
     
            for (int c=0; c<choice[1];c++)
            {
                System.out.println();
                System.out.println("question : " + category [c]);
                System.out.println();
     
                System.out.printf("1]");
                option[c] = input.nextLine();
     
                System.out.printf("2]");
                option2[c] = input.nextLine();
     
                System.out.printf("3]");
                option3[c] = input.nextLine();
     
                System.out.printf("4]");
                option4[c] = input.nextLine();
     
                System.out.println();
                System.out.println("please set the answerto this question");
                System.out.print("the answer is ");
                answer[c]= input.nextInt();
                input.nextLine();
                System.out.println();
            }
            System.out.println("your quiz game is now ready...press the enter to start ");
            input.nextLine();
            System.out.print('\u000C');
     
            System.out.printf(" welcome to game quiz");
            System.out.printf("Game rule; 1] select 1 topic");
            System.out.printf("2] answer the mcq question");
            System.out.printf("3] each correct answer will given 10 point");
            System.out.printf("4] each incorrect answer will be deducted 10 point");
            System.out.printf("5] the game will be over once your answer the question wrongly");
            System.out.println();
            System.out.printf(" press the enter key to start the game...");
            input.nextLine();
            System.out.print('\u000C');
     
        }
    }


  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: missing return statement need help!!

    Please post the full text of the error message.

    Add the return statement that the compiler is asking for,
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    widowx (March 29th, 2013)

  4. #3
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: missing return statement need help!!


  5. The Following User Says Thank You to PhHein For This Useful Post:

    widowx (March 29th, 2013)

  6. #4
    Junior Member
    Join Date
    Mar 2013
    Posts
    15
    My Mood
    Confused
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: missing return statement need help!!

    sorry i didnt know that if it was same web site or link to this one

  7. #5
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: missing return statement need help!!

    It isn't, but you are wasting other people's time.
    Just imagine you got a reply on the other site and a user here thinks about your problem to give you the same answer. It's inconsiderate and rude.

  8. The Following User Says Thank You to PhHein For This Useful Post:

    widowx (March 29th, 2013)

  9. #6
    Junior Member
    Join Date
    Mar 2013
    Posts
    15
    My Mood
    Confused
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: missing return statement need help!!

    the coding was ok but the is an error on missing return statement ... at the end of coding.
    i did try to delete or add "}" but i give the same error..
    i didnt know if it was related to boolean because we havent learn about boolean in school.
    errror 2.png

  10. #7
    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: missing return statement need help!!

    Did you add the missing return? Is the problem fixed now?
    If you don't understand my answer, don't ignore it, ask a question.

  11. The Following User Says Thank You to Norm For This Useful Post:

    widowx (March 29th, 2013)

  12. #8
    Junior Member
    Join Date
    Mar 2013
    Posts
    15
    My Mood
    Confused
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: missing return statement need help!!

    not yet....i search google about missing return statement. there alot of which make me confusing..

    error 3.png

  13. #9
    Junior Member
    Join Date
    Feb 2013
    Location
    N. Ireland
    Posts
    29
    Thanks
    2
    Thanked 6 Times in 6 Posts

    Default Re: missing return statement need help!!

    You don't seem to require a return statement for your code. You only have 1 method declared. I take it your using BlueJ. Just take a look at how you have declared your main method.

  14. The Following User Says Thank You to StephenCoyle For This Useful Post:

    widowx (March 27th, 2013)

  15. #10
    Junior Member
    Join Date
    Mar 2013
    Posts
    15
    My Mood
    Confused
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: missing return statement need help!!

    which part of my coding..

  16. #11
    Junior Member
    Join Date
    Feb 2013
    Location
    N. Ireland
    Posts
    29
    Thanks
    2
    Thanked 6 Times in 6 Posts

    Default Re: missing return statement need help!!

    check over your code and make sure you have the basic outline for java typed out correctly. Remember that Java is case sensitive.

  17. The Following User Says Thank You to StephenCoyle For This Useful Post:

    widowx (March 27th, 2013)

  18. #12
    Member Chris.Brown.SPE's Avatar
    Join Date
    May 2008
    Location
    Fort Wayne, Indiana
    Posts
    190
    Thanks
    1
    Thanked 31 Times in 31 Posts

    Default Re: missing return statement need help!!

    You have "void" capitalized as "Void". Is it possibly seeing this as a type and trying to make you have a return statement? It should be all lowercase. Give that a shot and see what happens. Also noticed you dont have a space between "String[]" and "args". Other than that i see no blatant errors in your code.
    Writing code is your job, helping you fix and understand it is mine.

    <-- Be sure to thank and REP (Star icon) those who have helped you. They appreciate it!

  19. The Following User Says Thank You to Chris.Brown.SPE For This Useful Post:

    widowx (March 27th, 2013)

  20. #13
    Junior Member
    Join Date
    Mar 2013
    Posts
    15
    My Mood
    Confused
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: missing return statement need help!!

    ok i try check my coding again...

    --- Update ---

    thnk for help..

  21. #14
    Junior Member
    Join Date
    Feb 2013
    Location
    N. Ireland
    Posts
    29
    Thanks
    2
    Thanked 6 Times in 6 Posts

    Default Re: missing return statement need help!!

    the typing error of Void instead of void is the problem. Your code will compile when you change it (I have BlueJ and it compiles). I don't think I could have directly told you as I have a mark against me for spood feeding and wasn't sure if I could or not.

  22. The Following User Says Thank You to StephenCoyle For This Useful Post:

    widowx (March 27th, 2013)

  23. #15
    Member Chris.Brown.SPE's Avatar
    Join Date
    May 2008
    Location
    Fort Wayne, Indiana
    Posts
    190
    Thanks
    1
    Thanked 31 Times in 31 Posts

    Default Re: missing return statement need help!!

    Is informing someone about a typo really spoon feeding? I have no problem of changing future advise. The line between spoon feeding and wasting people's time due to stupid errors is hard to define.
    Writing code is your job, helping you fix and understand it is mine.

    <-- Be sure to thank and REP (Star icon) those who have helped you. They appreciate it!

  24. The Following User Says Thank You to Chris.Brown.SPE For This Useful Post:

    widowx (March 27th, 2013)

  25. #16
    Junior Member
    Join Date
    Feb 2013
    Location
    N. Ireland
    Posts
    29
    Thanks
    2
    Thanked 6 Times in 6 Posts

    Default Re: missing return statement need help!!

    Quote Originally Posted by Chris.Brown.SPE View Post
    Is informing someone about a typo really spoon feeding? I have no problem of changing future advise. The line between spoon feeding and wasting people's time due to stupid errors is hard to define.
    Thanks for letting me know. I just wasn't sure and didn't want to take the chance.

  26. The Following User Says Thank You to StephenCoyle For This Useful Post:

    widowx (March 29th, 2013)

  27. #17
    Junior Member
    Join Date
    Mar 2013
    Posts
    15
    My Mood
    Confused
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: missing return statement need help!!

     
    /**
     * Write a description of class state here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    import java.util.*;
    import java.io.*;
    import java.util.Scanner;
    public class state
    {
        public static void main(String [] args)throws FileNotFoundException
        {
        Scanner input=new Scanner(System.in);
     
     
     String s =" ";
     String[] data, category, option,option2,option3,option4;
     data = new String [50];
     category = new String[50];
     option = new String [50];
     option2 = new String [50];
     option3 = new String [50];
     option4 = new String [50];
     int numq;
     
     
     
     
     int [] choice, answer;
     choice = new int[50];
     answer = new int[50];
     String in;
     
     
     
    System.out.printf(" Welcome to Quiz",s);
    System.out.printf("What to do?",s);
     
    System.out.printf("1]Specify number of question you want to do");
     
    System.out.printf("2]Enter the question CATEGORY");
     
    System.out.printf("3]Enter the QUESTION for each category");
     
    System.out.printf("4]Enter the OPTION for each question");
     
    System.out.printf("5]Provide the ANSWER for each question");
     
    System.out.printf("6]Then your QUIZ GAME is ready to be play by your friend");
     
    System.out.printf("Press any key to start the game..");
    System.out.println();
     
     
     
           System.out.println("How many question you want to create:");
           choice[1]=input.nextInt();
           System.out.println();
           System.out.print("\f");
           input.nextLine();
           System.out.println("Please enter your question CATEGORY");
     
           for (int a=0; a<choice[1];a++)
           {
               System.out.print(choice[2]+1+"]  ");
               data[a]=input.nextLine();
               choice[2]=choice [2] + 1;
            }
            System.out.print('\u000C');
            System.out.println();
            System.out.println("Please enter your Question");
     
            for (int  b=0; b<choice[1];b++)
            {
     
                System.out.println();
                System.out.println(" Category: " + data[b]);
                System.out.printf(choice[3] + 1 +" ] ");
                category[b]=input.nextLine();
                choice[3]=choice[3]+ 1;
            }
            System.out.print('\u000C');
            System.out.println();
            System.out.println("Please enter your question option ");
     
            for (int c=0; c<choice[1];c++)
            {
                System.out.println();
                System.out.println("question : " + category [c]);
                System.out.println();
     
                System.out.printf("1]");
                option[c] = input.nextLine();
     
                System.out.printf("2]");
                option2[c] = input.nextLine();
     
                System.out.printf("3]");
                option3[c] = input.nextLine();
     
                System.out.printf("4]");
                option4[c] = input.nextLine();
     
                System.out.println();
                System.out.println("please set the answerto this question");
                System.out.print("the answer is ");
                answer[c]= input.nextInt();
                input.nextLine();
                System.out.println();
            }
     
            System.out.println("your quiz game is now ready...press the enter to start ");
            input.nextLine();
            System.out.print('\u000C');
     
     
            System.out.println(" welcome to game quiz");
     
            System.out.println("Game rule; 1] select 1 topic");
     
            System.out.println("2] answer the mcq question");
     
            System.out.println("3] each correct answer will given 10 point");
     
            System.out.println("4] each incorrect answer will be deducted 10 point");
     
            System.out.println("5] the game will be over once your answer the question wrongly");
     
            System.out.println();
            System.out.printf(" press the enter key to start the game...");
            input.nextLine();
     
            System.out.print("\f");
     
     
     
    int Scorepoint= 0;
    int rounds =0;
     
     
     while(rounds < numberofquiz)
     {
     System.out.println("please select a Category.");
      System.out.println("Your current point is :" +Point);
      {
      for (int i=0; i <choice[1]; i++);
    }
      int choice[2]=userInput.nextInt();
     
      System.out.println(question[pickcategory]);
      System.out.println("1]" + option1[pickcategory]); 
      System.out.println("2]" + option2[pickcategory]); 
      System.out.println("3]" + option3[pickcategory]); 
      System.out.println("4]" + option4[pickcategory]); 
      System.out.println("what is your answer");
      int playerans = userinput.nextInt();
     
      if (playerans =answer[pickcategory]
      {
          System.out.print("\f");
          System.out.println("your answer is correct");
          System.out.println("the answer is:" + answer[pickcategory];
          System.out.println();
          Scorepoint += 10;
          round += 1;
        }
        else
        {
         System.out.print("\f");
         System.out.println("your answer is incorrect.");
         System.out.println("the answer is :" + answer[pickcategory]);
         System.out.println();
         Scorepoint -=10;
         rounds = NumberofQuestion;
        }
     
        playerans =0;
        pickcategory = 0;
    }
    System.out.print("\f");
    System.out.println("game Over");
    System.out.println("your score:" + Scorepoint);
    }
    }

    hi.. need help. here my full coding on game quiz i have a problem on( ']' expected) on bluej
    here image:error 4.png

  28. #18
    Member Chris.Brown.SPE's Avatar
    Join Date
    May 2008
    Location
    Fort Wayne, Indiana
    Posts
    190
    Thanks
    1
    Thanked 31 Times in 31 Posts

    Default Re: missing return statement need help!!

    The problem there is that you've already declared that array prior to this line. You dont need the word "int" before you access an array. When you get past that you have a lot of errors from missing parenthesis to undeclared variables.
    Writing code is your job, helping you fix and understand it is mine.

    <-- Be sure to thank and REP (Star icon) those who have helped you. They appreciate it!

  29. The Following User Says Thank You to Chris.Brown.SPE For This Useful Post:

    widowx (March 28th, 2013)

  30. #19
    Junior Member
    Join Date
    Mar 2013
    Posts
    15
    My Mood
    Confused
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: missing return statement need help!!

    what it meant by " int cannot be dereferenced". i got this error.
    error redo.jpg

  31. #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: missing return statement need help!!

    int cannot be dereferenced
    An int is not an object and does not have any methods you can call using an int variable. For example:
    int x = 1;
    x.size();  // int cannot be dereferenced
    If you don't understand my answer, don't ignore it, ask a question.

  32. The Following User Says Thank You to Norm For This Useful Post:

    widowx (March 28th, 2013)

  33. #21
    Junior Member
    Join Date
    Mar 2013
    Posts
    15
    My Mood
    Confused
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: missing return statement need help!!

    ok..i try check again my coding..

  34. #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: missing return statement need help!!

    check again my coding
    If there are error messages, copy the full text and paste it here.
    Otherwise please explain what the problem is.
    If you don't understand my answer, don't ignore it, ask a question.

  35. The Following User Says Thank You to Norm For This Useful Post:

    widowx (March 28th, 2013)

  36. #23
    Junior Member
    Join Date
    Mar 2013
    Posts
    15
    My Mood
    Confused
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: missing return statement need help!!

    incompatible types -found int but expected boolen.. i did not know what does this meant..
    error 7.jpg
     
    /**
     * Write a description of class state here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    import java.util.*;
    import java.io.*;
    import java.util.Scanner;
    public class state
    {
        public static void main(String [] args)throws FileNotFoundException
        {
        Scanner input=new Scanner(System.in);
     
     
     String s =" ";
     String[] data, category, option,option2,option3,option4;
     data = new String [50];
     category = new String[50];
     option = new String [50];
     option2 = new String [50];
     option3 = new String [50];
     option4 = new String [50];
     int numq;
     
     
     
     
     int [] choice, answer;
     choice = new int[50];
     answer = new int[50];
     String in;
     
     
     
    System.out.printf(" Welcome to Quiz",s);
    System.out.printf("What to do?",s);
     
    System.out.printf("1]Specify number of question you want to do");
     
    System.out.printf("2]Enter the question CATEGORY");
     
    System.out.printf("3]Enter the QUESTION for each category");
     
    System.out.printf("4]Enter the OPTION for each question");
     
    System.out.printf("5]Provide the ANSWER for each question");
     
    System.out.printf("6]Then your QUIZ GAME is ready to be play by your friend");
     
    System.out.printf("Press any key to start the game..");
    System.out.println();
     
     
     
           System.out.println("How many question you want to create:");
           choice[1]=input.nextInt();
           System.out.println();
           System.out.print("\f");
           input.nextLine();
           System.out.println("Please enter your question CATEGORY");
     
           for (int a=0; a<choice[1];a++)
           {
               System.out.print(choice[2]+1+"]  ");
               data[a]=input.nextLine();
               choice[2]=choice [2] + 1;
            }
            System.out.print('\u000C');
            System.out.println();
            System.out.println("Please enter your Question");
     
            for (int  b=0; b<choice[1];b++)
            {
     
                System.out.println();
                System.out.println(" Category: " + data[b]);
                System.out.printf(choice[3] + 1 +" ] ");
                category[b]=input.nextLine();
                choice[3]=choice[3]+ 1;
            }
            System.out.print('\u000C');
            System.out.println();
            System.out.println("Please enter your question option ");
     
            for (int c=0; c<choice[1];c++)
            {
                System.out.println();
                System.out.println("question : " + category [c]);
                System.out.println();
     
                System.out.printf("1]");
                option[c] = input.nextLine();
     
                System.out.printf("2]");
                option2[c] = input.nextLine();
     
                System.out.printf("3]");
                option3[c] = input.nextLine();
     
                System.out.printf("4]");
                option4[c] = input.nextLine();
     
                System.out.println();
                System.out.println("please set the answerto this question");
                System.out.print("the answer is ");
                answer[c]= input.nextInt();
                input.nextLine();
                System.out.println();
            }
     
            System.out.println("your quiz game is now ready...press the enter to start ");
            input.nextLine();
            System.out.print('\u000C');
     
     
            System.out.println(" welcome to game quiz");
     
            System.out.println("Game rule; 1] select 1 topic");
     
            System.out.println("2] answer the mcq question");
     
            System.out.println("3] each correct answer will given 10 point");
     
            System.out.println("4] each incorrect answer will be deducted 10 point");
     
            System.out.println("5] the game will be over once your answer the question wrongly");
     
            System.out.println();
            System.out.printf(" press the enter key to start the game...");
            input.nextLine();
     
            System.out.print("\f");
     
     
     
    int Scorepoint= 0;
    int rounds =0;
    int c=50;
     
     
     while(rounds < choice[1])
     {
     System.out.println("please select a Category.");
      System.out.println("Your current point is :" +Scorepoint);
      {
      for (int i=0; i <choice[1]; i++);
    }
      choice[2]=choice[1];
     
      System.out.println(data);
      System.out.println("1]" + option); 
      System.out.println("2]" + option2); 
      System.out.println("3]" + option3); 
      System.out.println("4]" + option4); 
      System.out.println("what is your answer");
      int playerans = choice[2];
     
      if (playerans = answer[c])
      {
          System.out.print("\f");
          System.out.println("your answer is correct");
          System.out.println("the answer is:" + answer[pickcategory]);
          System.out.println();
          Scorepoint += 10;
          round += 1;
        }
    else
        {
         System.out.print("\f");
         System.out.println("your answer is incorrect.");
         System.out.println("the answer is :" + answer[pickcategory]);
         System.out.println();
         Scorepoint -=10;
         rounds = NumberofQuestion;
        }
     
        playerans =0;
        pickcategory = 0;
    }
    System.out.print("\f");
    System.out.println("game Over");
    System.out.println("your score:" + Scorepoint);
    }
    }

    here my full coding on game quiz.

  37. #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: missing return statement need help!!

    found int but expected boolen
    The compiler found an int value/variable where it expected a boolean variable/value.

    Can you post the full text of the error message that shows the statement with the error?
    Here is a sample of a compiler error message:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    If you don't understand my answer, don't ignore it, ask a question.

  38. The Following User Says Thank You to Norm For This Useful Post:

    widowx (March 29th, 2013)

  39. #25
    Junior Member
    Join Date
    Mar 2013
    Posts
    15
    My Mood
    Confused
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: missing return statement need help!!

    How can I post compiler error. Is it same like post java coding...or the different methods. .

Page 1 of 2 12 LastLast

Similar Threads

  1. Missing return statement
    By beerye28 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 23rd, 2013, 06:48 PM
  2. Missing return statement
    By mrroberts2u in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 10th, 2011, 06:11 AM
  3. Missing return statement
    By Stn in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 1st, 2011, 08:03 PM
  4. Prime number generator program missing return statement
    By 03EVOAWD in forum What's Wrong With My Code?
    Replies: 13
    Last Post: September 10th, 2009, 09:17 AM
  5. Error of "Class has no return statement"
    By mdstrauss in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 2nd, 2009, 12:00 PM