• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

want a better code

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I have worked out a problem to find the winner and second runner up of a marathon.However, I would like to know a more efficient method to get the runner up of the race.Method which I have employed to accomplish this task is to remove the data of the winner of the race and then to determine the winner of our modified list.



[Added code tags - see UseCodeTags for details]
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well the object oriented way to do it is to create a class to hold a participant name and their time.
You also make this class implement the Comparable interface.
You then create an instance of this class for each person and add these instances to a List. You then sort this list after which the first entry in the list will be the winner and the second entry will be the runner up.

However, if none of that makes any sense to you yet, then the simple way to do it at the moment is to just add a second pair of variables to hold the name and time of the runner up and then set these in a similar way to how you are currently setting the winner's name and time in the min1 and name1 variables.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Edit: Whoops. Meant to edit my previous post, not quote it.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Devesh Gurjar wrote:Hello


Devesh,

1. Welcome to JavaRanch.
2. Please DontWriteLongLines. I've broken yours up this time.

Winston
 
reply
    Bookmark Topic Watch Topic
  • New Topic