• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Class not working?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic