
-----------------------------------
magicman
Wed May 31, 2006 11:22 am

public static....
-----------------------------------
i have a program that i have to make for my end project and i need alittle help with it. so far this is what i have.


public static int stage1 ()
    {
        int stg1;
        stg1 = (int) (Math.random () * 2) + 1;
        String answer;


        switch (stg1)
        {

            case 1:
                c.println ("question");
                c.print ("A)fhdskjahf");
                c.println ("     B)fdsafds");
                c.print ("C)fdsafdsa");
                c.println ("     D)fgdsawer");
                answer = c.readString ();
                if (answer.equals ("a") | answer.equals ("A"))
                {
                    c.println ("Is that the final answer??");
                    c.println ("y/n");
                    answer = c.readString ();
                    if (answer.equals ("y") | answer.equals ("Y"))
                    {
                        c.println ("You have won $100");
                        break;
                    }
                    else
                        if (answer.equals ("n") | answer.equals ("N"))
                        {
                        }

                }


            case 2:
                c.println ("question2");
                c.print ("A)fhdskjahf");
                c.println ("     B)fdsafds");
                c.print ("C)fdsafdsa");
                c.println ("     D)fgdsawer");
                break;
        }
    }


its giving me a dumb @$$ error, 
The Method "int stage1();" must contain a return statement with an expression compatible with type "int".

how do i fix it???


and if you see any thing else that i should do, please speak up.

-----------------------------------
md
Wed May 31, 2006 11:38 am


-----------------------------------
you need to return an int with the return statement ;)

-----------------------------------
magicman
Wed May 31, 2006 11:41 am


-----------------------------------
Common man, thats not even funny...
i would like some REAL HELP!!!!!

-----------------------------------
wtd
Wed May 31, 2006 12:02 pm


-----------------------------------
I'm guessing that you have absolutely no idea why there's an "int" in "public static int"".

This is a phenomenally important concept to understand.  Read my Introduction to Java.  It's available in the Java Tutorials forum.

-----------------------------------
md
Wed May 31, 2006 12:38 pm


-----------------------------------
I was serious. It's a very clear error message.

-----------------------------------
codemage
Wed May 31, 2006 12:54 pm


-----------------------------------
Enough of the slack jawed non-helpful comments.  Read below for some super-secret REAL help:

You need to return an int with the return statement.

-----------------------------------
wtd
Wed May 31, 2006 1:26 pm


-----------------------------------
Enough of the slack jawed non-helpful comments.  Read below for some super-secret REAL help:

You need to return an int with the return statement.

Mine was not a non-helpful comment.

This is a fine suggestion, except that it does not address the (suspected) underlying issue, which is connecting the "int" in "public static int" with the method returning an int.

If a programmer can "get" that, then it's a simple matter to realize that "public static String" for instance means the method has to return a String.

Then of course you have to understand what public and static mean.  :)
