Back in the day I tried to learn C++, but I was younger and patience wasn't my virtue. After that I tried out scripting for NWN and found that to be fun, but my computer died and I lost interest.
After playing Minecraft and Dwarf Fort recently, my interest in learning a programing language has been rekindled and it seems like Java is a good place to start. I'm 23 btw.
So heres the breakdown:
After deciding to try this out I went to the net to find a book, got myself a copy of Head First and I'm on the Guess Game Tut.
Here's what I have:
After getting 23 errors in the code I was able to widdle it down to 2 on my own. I'm using Eclipse for this. Was gonna use notpad and the JDK compiler but I couldn't figure that out on my own. This what I'm having trouble with in the code now.
Its telling me the 'The public type Player has to be defined in its own file."
Same for this (only with GameLauncher):
Now the tut doesn't specify this. I have it all in one Java doc. How do I solve this?
Now the book is done 1.5 I'm using 1.6 Is this my problem? What am I missing? Are my classes defined right? I'm also not to sure what the method and classes are here. Same for the instance variable.
Thank you to anyone who has taken the time to read this, and great thanks to anyone who takes the time to help a clueless self teaching student.
The error message that you got tells you how to solve it: "The public type Player has to be defined in its own file."
In Java, public classes must be in their own source file, which has the same name as the public class and the ".java" extension. So, don't put all the code in one source file, but create separate source files for each class (GuessGame.java, Player.java and GameLauncher.java).
It doesn't have anything to do with using Java 6 instead of Java 5.
Have a look at the Oracle Java tutorials I posted a link to, especially the chapter Learning the Java Language, which explains the basics of classes, objects, variables, methods etc. It might be better to start with some smaller examples that focus on those basic concepts before you start working with a more complicated program - don't try to learn too much at once.
Greg Mark wrote:I'll do that, thank you. I wasn't sure about what it meant by file.
Now, GuessGame, Player, and GameLaunch are my classes, right?
Then this here would be my instance variable? . . .
In that case, in the GuessGame class, the instance variables are P1 P2 and P3 (actually, under style conventions that should be p1 p2 p3). You appear to have three of them. The variables p1Guess, p1IsRight, etc appear to be local variables in the startGame method.
In the Player class, there is the guess variable (1 instance field) and in the GameLauncher class, you haven't got any instance variables.
When you got the Head First book, I presume you got the 2nd edition? That uses Java5 (1.5); you won't notice much difference in Java6 (1.6) at this stage.
Don't use MS Notepad; it isn't very good for programming. Try Notepad2, jEdit or Notepad++, which are all much better. Enable such options as syntax highlighting and bracket matching and automatic indentation (1 tab automatically changed to 4 spaces).
Try this on the command line
mkdir java_work [or similar]
[Edit the three files and save them in the java_work directory.]
This will only work if you have set your PATH correctly; if it doesn't, you will find help in this Java™ Tutorials section, particularly "common problems". The first error message tells what happens if you don't set your PATH.
Don't set a system classpath.