• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help wtih this code!

 
bob michelle
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
been working on this all day..so tired i cant focus on it anymore maybe somebody can help

 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And your question is ?
 
Nico Van Brandt
Ranch Hand
Posts: 70
IntelliJ IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..

     
    fred rosenberger
    lowercase baba
    Bartender
    Posts: 12143
    30
    Chrome Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic