Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

need help wtih this code!

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
been working on this all day..so tired i cant focus on it anymore maybe somebody can help

 
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And your question is ?
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..

     
    lowercase baba
    Posts: 13048
    67
    Chrome Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    I yam what I yam and that's all that I yam - the great philosopher Popeye. Tiny ad:
    free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
    reply
      Bookmark Topic Watch Topic
    • New Topic