• Post Reply Bookmark Topic Watch Topic
  • New Topic

Please help with game  RSS feed

 
Li Brown
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I compile my code a javac asks me that I have 2 errors?These errors call identical -"class,interface or enum expected import.java.util.*"one error locate in 75th row, second in 135th row.
My code:
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your import statements are not in the correct place in the source file:

http://docs.oracle.com/javase/tutorial/java/package/usepkgs.html
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch. Please take note of Bear's message.

you should not put all of this code in one source file.

You need to make two source files: GameHelper.java, which contains line 1 to 73, and DotComBust.java, which contains lines 75 to 156.
 
Li Brown
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:Welcome to the Ranch. Please take note of Bear's message.

You should not put all of this code in one source file.

You need to make two source files: GameHelper.java, which contains line 1 to 73, and DotComBust.java, which contains lines 75 to 156.

How I'm launching two source files together?
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't use package names, simply put all the .java files in the current directory and compile with class with the main method in. The javac tool will find all required files.
 
Li Brown
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:If you don't use package names, simply put all the .java files in the current directory and compile with class with the main method in. The javac tool will find all required files.

I use Eclipse and notepad, how I can create directory in these programs and put my .java files in them?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Li Brown wrote:I use Eclipse and notepad, how I can create directory in these programs and put my java files in them?

That seems odd. Eclipse and Notepad are normally mutually exclusive. In Eclipse, you would create a new package, which will create a new directory for you behind the scenes. You can't create a new directory in Notepad, but you certainly can from the command line.

Winston
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Li Brown wrote:How I'm launching two source files together?

You compile both of them, and then you run the one that contains the public static void main(String[] args) method.

Note: You actually need three source files. The class DotCom (lines 137 - 156) also needs to be in a separate source file named DotCom.java.

In a source file, import statements must always be above the class definition. You can have only one public top-level class in a source file, and the source file has to have the same name as that class.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are not using package names, you do not need a new directory. I suggest you follow the procedure for creating a “java” directory in this old post.
 
Li Brown
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Li Brown wrote:When I compile my code a javac asks me that I have 2 errors?These errors call identical -"class,interface or enum expected import.java.util.*"one error locate in 75th row, second in 135th row.
My code:

With your assistance I solved this problem.Thank you very much!!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!