• 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

Any defect in the attached code

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI GUys,

Can you spot any issues on the below code apart from the one i spotted(in bold)...

 
Saloon Keeper
Posts: 13865
313
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like someone is already reviewing this code for you. Why do you want us to look at it?
 
Arun Chidam
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:It looks like someone is already reviewing this code for you. Why do you want us to look at it?




Yes it was me who reviewed the code, I want to know if anything i missed in my review???
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What kind of issues?
 
Stephan van Hulst
Saloon Keeper
Posts: 13865
313
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And please just post the fixed code. Not much point it looking for mistakes in code that is obviously mistaken.
 
Arun Chidam
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:And please just post the fixed code. Not much point it looking for mistakes in code that is obviously mistaken.



Updated the fixed code....

 
Arun Chidam
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:What kind of issues?



i am looking for runtime error(if any)?
Also is there any better way of coding the sort method?
 
Stephan van Hulst
Saloon Keeper
Posts: 13865
313
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you can just make your Name class implement Comparable, and then use the Collections.sort() method.

I assume you're implementing your own sort method as an exercise though. Anyway, there are several things you could consider wrong. Your method

1) is destructive, it destroys the list you pass into it. This is not considered very wanted behavior.
2) discards names that are 'greater' than "zzz, zzz", and inserts this name instead.
3) creates new instances for each name in the list, and adds them to the new list. Why not add the names directly?
4) uses a do-while loop. Don't use do-while loops. Use while loops instead.

Your Name class implements equals() wrongly, and on top of that, it doesn't implement hashCode(). Read the contract for Object.equals() and Object.hashCode().
 
Arun Chidam
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI stephan, thanks a lot for your comments....your reviews are very helpful
 
Get me the mayor's office! I need to tell her about this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic