Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class not working?

 
Amos Tham
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
C1.displayDetails();
}}
______________________________________________________________________
can anyone pleas help me thx!!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
bear
P.S. Use of the UBB code tags to surround your code will preserve its formatting.
 
Ken Cobbs
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

It looks to me that if you removed that top
"public static void main (String args[]) {"
it should work fine.
Have fun!
 
Spike Spiegel
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, the method name is displaTDetails (with a (2) t's), while the call is .displayDetails (with a y and only one t).
Regards,
Hans
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Regards,
Jeff
[ August 21, 2003: Message edited by: Jeff Bosch ]
[ August 21, 2003: Message edited by: Jeff Bosch ]
 
rom chatterjee
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic