File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Class not working? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Class not working?" Watch "Class not working?" New topic

Class not working?

Amos Tham

Joined: Aug 18, 2003
Posts: 3
Hi this class is not working what is the problem

class ClassDemo {
public static void main (String args[]){
String bookID = "A100";
String title = "Java for beginners";
String author = "AMos Tham";
String Publisher = "Tecman";
int edition = 3;
float price = 25.50f;
public void displatDetails(){
System.out.println("The book ID is" + bookID);
System.out.println("The title is" + title);
System.out.println("The auhthor is" + auhtor);
System.out.println("The publisher is " + publisher);
System.out.println("The edition is" + edition)
System.out.println("The book price is " + price);
public static void main (String args[]){
ClassDemo c1 = new ClassDemo();
can anyone pleas help me thx!!
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

Hi Amos,
Welcome to the Ranch!
"not working" is pretty broad and not helpful. How is it "not working"? Some details as to what you expect it to do, and what it does will get you better responses.
P.S. Use of the UBB code tags to surround your code will preserve its formatting.

[Asking smart questions] [About Bear] [Books by Bear]
Ken Cobbs

Joined: Jun 18, 2002
Posts: 29

It looks to me that if you removed that top
"public static void main (String args[]) {"
it should work fine.
Have fun!
Spike Spiegel

Joined: Aug 20, 2003
Posts: 20
Also, the method name is displaTDetails (with a (2) t's), while the call is .displayDetails (with a y and only one t).
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 805
Hi, Amos -
You have several problems in the code: a typo in a method call, two main() methods, which is illegal, and mismatched curly braces. For every opening brace '{', you need one closing brace '}'.
One of the biggest problems beginning programmers have to overcome seems to be the "fatfinger" syndrome. While we know what we meant when we wrote the program, the compiler can only work with what we wrote. Maybe someday someone will invent the "DoWhatIMeantNotWhatIWrote" compiler, but probably not.
Careful attention to detail is a requirement for good programming.
[ August 21, 2003: Message edited by: Jeff Bosch ]
[ August 21, 2003: Message edited by: Jeff Bosch ]

Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
rom chatterjee
Ranch Hand

Joined: Dec 11, 2001
Posts: 46
Just something elese to think about. You may wamt to think a bit more about your class structure in simple terms (its never too soon!).
Try making your ClassDemo a Book class (thats what it seems to be). Then all the attributes (title,author, etc) should be made private and accessor methods used for setting and getting the values.

Then add a toString() method, which is what I think you were originally doing. All your future classes should have a toString() method. There is a book (Effecitve Java: 50 ways to improve your programming) That has good advice for general class design/usage).
Lastly you can add a main method to the Book class to test it the method can create a Book set its attributes, get them and finally call toString(). Alternatively have an other class purely for creating and using a book.

When you're ready (there's no rush) check out JUnit for testing your classes

Rom Chatterjee<BR>Sun Certified Java Programmer
I agree. Here's the link:
subject: Class not working?
It's not a secret anymore!