Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 public static....
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
magicman




PostPosted: Wed May 31, 2006 11:22 am   Post subject: 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.

code:

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.
Sponsor
Sponsor
Sponsor
sponsor
md




PostPosted: Wed May 31, 2006 11:38 am   Post subject: (No subject)

you need to return an int with the return statement Wink
magicman




PostPosted: Wed May 31, 2006 11:41 am   Post subject: (No subject)

Common man, thats not even funny...
i would like some REAL HELP!!!!!
wtd




PostPosted: Wed May 31, 2006 12:02 pm   Post subject: (No subject)

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




PostPosted: Wed May 31, 2006 12:38 pm   Post subject: (No subject)

I was serious. It's a very clear error message.
codemage




PostPosted: Wed May 31, 2006 12:54 pm   Post subject: (No subject)

Enough of the slack jawed non-helpful comments. Read below for some super-secret REAL help:

Quote:
You need to return an int with the return statement.
wtd




PostPosted: Wed May 31, 2006 1:26 pm   Post subject: (No subject)

codemage wrote:
Enough of the slack jawed non-helpful comments. Read below for some super-secret REAL help:

Quote:
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. Smile
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: