Results 1 to 6 of 6
Thread: class interface error
- 10-28-2010, 12:15 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 25
- Rep Power
- 0
- 10-28-2010, 12:30 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,540
- Rep Power
- 11
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.
- 10-28-2010, 12:49 AM #3
Member
- Join Date
- Oct 2010
- Posts
- 25
- Rep Power
- 0
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:
The compiler is saying class, interface, or enum expected hereJava 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; }
Java Code:int getFace()
- 10-28-2010, 01:00 AM #4
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 :)
- 10-28-2010, 01:21 AM #5
Member
- Join Date
- Oct 2010
- Posts
- 25
- Rep Power
- 0
ok I set it up wrong. We are just starting this chapter. Thanks.
- 10-28-2010, 01:23 AM #6
Similar Threads
-
keep getting error message class, interface, or enum expected
By darr in forum New To JavaReplies: 2Last Post: 10-02-2010, 02:13 AM -
Annoying problem class/interface error
By Chick786 in forum New To JavaReplies: 2Last Post: 04-11-2010, 04:36 PM -
E:\IT 215 Java Programming\public class Inventory.java:39: class, interface, or enum
By tlouvierre in forum New To JavaReplies: 14Last Post: 05-28-2009, 05:44 AM -
what is the Priority for execution of Interface class and a Abstract class
By Santoshbk in forum Advanced JavaReplies: 0Last Post: 04-02-2008, 07:04 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks