*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "need help wtih this code!" Watch "need help wtih this code!" New topic
Author

need help wtih this code!

bob michelle
Greenhorn

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

Joanne Neal
Rancher

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


Joanne
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
    Bartender

    Joined: Oct 02, 2003
    Posts: 11170
        
      16

    Nico,

    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
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    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