| Author |
want a better code
|
Devesh Gurjar
Greenhorn
Joined: Jan 24, 2013
Posts: 1
|
|
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]
|
 |
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
|
|
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
|
 |
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
|
|
|
Edit: Whoops. Meant to edit my previous post, not quote it.
|
 |
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 4898
|
|
Devesh Gurjar wrote:Hello
Devesh,
1. Welcome to JavaRanch.
2. Please DontWriteLongLines. I've broken yours up this time.
Winston
|
Isn't it funny how there's always time and money enough to do it WRONG?
|
 |
 |
|
|
subject: want a better code
|
|
|