• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Has anyone done the GuessGame program in HeadFirst Java?

 
Rita Chakras
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a little confused. The program has three classes. Do the three classes go in the same file? Or seperate files? If seperate, how do they find/talk to each other?

Just curious... not even sure if the code is supposed to work given the way it shown in the book.

Any help appreciated!

Thanks!
Rita C
 
Karthikeyan Rajendraprasad
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have not seen the program.. but i can give an answer for your question.

simple rule is that if the class is defined as public it should be saved in a file with the same name. for eg

will be saved in a file called as Quiz.java

in other cases it can be placed along with any other classes.

the way the programs communicate is that the class file will be searched in the classpath.
 
Steve Morrow
Ranch Hand
Posts: 657
Clojure Spring VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also pick up the actual source code here:

http://www.wickedlysmart.com/HeadFirst/HeadFirstJava/code/codeKitchensTiger.jar
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The program has three classes. Do the three classes go in the same file? Or seperate files? If seperate, how do they find/talk to each other?

It's usually best to put each class in its own file. Whether or not they are in the same source file, when you compile them with the "javac" command, they will become three separate ".class" files. The class files "find each other" by using the classpath when you run them with the "java" command.
 
Megs Maquito
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All three classes should be in the same directory.

I just noticed... I'm now a ranch hand
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just noticed, I'm still a ranch hand. I should be interim assistant secretary to the deputy trash collector by now. I feel a certain empathy with Fester on Gunsmoke.

For those not familiar with Gunsmoke, Fester was the deputy sheriff but also a world class producer whose works include The Giant Gila Monster. IMO, the cinematic equivalent of Chopin or Beethoven.

http://www.englewd.com/catalog/detail.cfm?ProdNum=59&GroupID=1
[ August 21, 2005: Message edited by: Rick O'Shay ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic