• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please help with game

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 79263
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79263
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic