File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Head First Java Beginnner's Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First Java Beginnner Watch "Head First Java Beginnner New topic
Author

Head First Java Beginnner's Question

Dan Reimer
Greenhorn

Joined: Jan 12, 2006
Posts: 4
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

Joined: Jan 10, 2006
Posts: 20
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

Joined: Jan 10, 2006
Posts: 20
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

Joined: Jan 12, 2006
Posts: 4
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

Joined: Jan 12, 2006
Posts: 4
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

Joined: Jan 10, 2006
Posts: 20
Hey, don't fret over it! Glad you got it workin'!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First Java Beginnner's Question