Results 1 to 6 of 6
  1. #1
    Latanyar is offline Member
    Join Date
    Oct 2010
    Posts
    25
    Rep Power
    0

    Default class interface error

    what does it mean when you get a class, interface, or enum expected error?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    It means the compiler has got *very* confused by some syntax error or other in your code.

    A very common cause of this is having braces that are unbalanced. Go through your code and make sure each { and } is exactly where you meant it to be.

    Another rule of thumb is to look for a syntax error (missing ;, bad {}, etc) just before the place where the compiler complains.

    If(f) all else fails post your code - remember to indicate which line of your code is being referred to in the compiler's message.

  3. #3
    Latanyar is offline Member
    Join Date
    Oct 2010
    Posts
    25
    Rep Power
    0

    Default

    Create a Dice class that has a face data field (that indicates the current value showing). The class should have a getFace method which returns the current value of face, and a roll method that chooses a random value for face. Write a main program that creates 2 Dice objects. The main program should roll both dice and display the value showing for each. Be sure to use proper style. Create a jar file of your program and attach to this assignment page.

    I just started, so this is what I have so far:

    Java Code:
    public class diceGame
    {
        public static void main(String[] args)
        {
            int dice1;
            int dice2;
        }
    }
    
    class dice
    {
       int face = 6;
    }
    
    // returns the current value of face
     int getFace()
     {
         return face;
     }
     
     
     int roll()
     {
        return (Math.random) + 7; 
     }
    The compiler is saying class, interface, or enum expected here
    Java Code:
    int getFace()

  4. #4
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    4

    Default

    You have this code outside of the classes. You have end brackets on all class code before it reaches that method. Also, you aren't declaring you methods correctly. They should like like:

    Java Code:
    private int getFace() // Or public int getFace(), etc...

    General layout for a program:

    Java Code:
    CLASS
    {
         Main Method
         {
         }
    
         Any Other Methods In That Class
         {
         }
    }
    Last edited by joshdgreen; 10-28-2010 at 01:02 AM.
    Sincerely, Joshua Green
    Please REP if I help :)

  5. #5
    Latanyar is offline Member
    Join Date
    Oct 2010
    Posts
    25
    Rep Power
    0

    Default

    ok I set it up wrong. We are just starting this chapter. Thanks.

  6. #6
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    4

    Default

    No problem, good luck :)
    Sincerely, Joshua Green
    Please REP if I help :)

Similar Threads

  1. Replies: 2
    Last Post: 10-02-2010, 02:13 AM
  2. Annoying problem class/interface error
    By Chick786 in forum New To Java
    Replies: 2
    Last Post: 04-11-2010, 04:36 PM
  3. Replies: 14
    Last Post: 05-28-2009, 05:44 AM
  4. Replies: 0
    Last Post: 04-02-2008, 07:04 AM

Posting Permissions

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