This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Head First Java Beginnner's Question

 
Dan Reimer
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried coding the DrumKit problem on page 43 into two files. DrumKit.java and DrumKitTestDrive.java. Is this the way that you can get this problem to run? I tried compiling both of them and I get an "error: cannot read: DrumKit.java" error. How do you set up muliple classes and get them to run?

[ January 12, 2006: Message edited by: Dan Reimer ]
 
Curtis Brown
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that you may need to compile them at the same time, or perhaps do DrumKit.java first so that the Test-Drive knows it's a valid class....

What error(s) are you getting? (the cannot read error is new to me... was the file closed, or perhaps you had it open still for editing???)
[ January 12, 2006: Message edited by: Curtis Brown ]
 
Curtis Brown
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just re-did this excersise (deleted the .class files) and was able to get the files to compile simply by typing:



Here are the two files: DrumKit.java:


And DrumKitTestDrive.java:
 
Dan Reimer
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess my question is: am I doing this the right way. I have created two classes. The first one is titled DrumKit.java and contains the following code:

class DrumKit {

boolean snare = true;
boolean topHat = true;

void playSnare() {
System.out.println("bang bang ba-bang");
}

void playTopHat() {
System.out.println("ding ding da-ding");
}
}

The second file is called DrumKitTestDrive.java and contains the following code:

class DrumKitTestDrive {

public static void main (String [] args) {

DrumKit d = new DrumKit();
d.playSnare();
d.snare = false;
d.playTopHat();

if (d.snare == true) {
d.playSnare();

}
}
}

I try to type javac DrumKit.java at the command prompt and I get the following error:

error: cannot read: DrumKit.java
1 error

The problem is found on page 43 of Head First Java and I was just trying to put it all together and run it to teach myself how you can run mulitple classes.
 
Dan Reimer
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Major brain fart, but I guess that is to be expected with a second day user of java. Forgot to cd my command prompt to the location of my java files. At least I won't forget what that error message refers to. Thanks for your help and sorry for wasting your time.
Dan
 
Curtis Brown
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, don't fret over it! Glad you got it workin'!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic