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 need help wtih this code! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "need help wtih this code!" Watch "need help wtih this code!" New topic

need help wtih this code!

bob michelle

Joined: Dec 15, 2011
Posts: 2
been working on this all tired i cant focus on it anymore maybe somebody can help

Joanne Neal

Joined: Aug 05, 2005
Posts: 3419
And your question is ?

Nico Van Brandt
Ranch Hand

Joined: Mar 31, 2011
Posts: 66

Your code works (you knew that already) but it is rubbish.

Some notes:
  • System.out.println("Error:..."). Apart from the fact System.err.println() exists, you should throw Exceptions
  • Don't repeat yourself: call the setters that do the checks. In this example it is safe to do so. (but you should be careful calling them from the constructor)
  • Group constructors and getters/setters for a better overview
  • writeOutput should not be in this class. Instead override the toString() method. Then when we call System.out.println(myPet), the return value of the toString() method gets printed.

  • There is more to say but just compare the solutions..

    Oracle Java SE6 Certified Programmer
    Oracle Java EE5 Certified Web Component Developer
    fred rosenberger
    lowercase baba

    Joined: Oct 02, 2003
    Posts: 11153


    Please don't post a complete solution to the problem. We encourage people to figure it out for themselves. Hint, suggest, or lead them to the answer, but please don't provide a fully implemented program.

    There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
    Consider Paul's rocket mass heater.
    subject: need help wtih this code!
    Similar Threads
    Using method on a program
    Displaying things...need help badly!! Please!
    exception in thread "main"
    Write and Read Records
    variables not found with OOP