Try to think a little more in terms of OOP (Object-Oriented Programming).
A Participant can participate in multiple Event's. Everytime a Participant participates in an Event, there is a Result that gets generated for that particular Participant and gets a corresponding score.
Now that I have the basic structure of how I want to layout my classes, so we can define specific behavior of how we want each class to go about.
public class Participant
{
private List<Event> events;
private String name;
public Participant( String name )
{
this.name = name;
events = new ArrayList<Event>();
}
//... other methods
public void participate( Event event )
{
double score;
//... get the score
events.add( event );
event.recordResult( this, score );
}
}
So now the Participant can participate in certain Event's that you define.
Now looking at what I did in that participate method, we need to have a way to store Result's inside of an Event.
public class Event
{
private List<Result> results;
public Event()
{
results = new ArrayList<Result>();
}
// ...
public void scoreResult( Participant participant, double score )
{
//if a participant cannot participate multiple times in an event, probably need a check to see if
//the participant is already in the list, otherwise update the score isntead of adding a new Result
results.add( new Result( participant, score ) );
}
}
So now each Event that you define has a way to score a Result for a particular Participant.
I'll just do the basic outline for a Result class
public class Result
{
private Participant participant;
private double score;
public Result( Participant participant, double score )
{
this.participant = participant;
this.score = score;
}
// ... getters and setters
}
This could be a basic outline for your Objects. Now you can define a method in Participant to get the best Result of all Event's he has participated in. Something like:
public Result getBestResult()
{
Result bestResult = null;
for( Event event : events )
{
if( bestResult == null )
bestResult = event.getResult();
if( bestResult.getScore() < event.getResult().getScore() )
bestResult = event.getResult();
}
//if the participant hasn't participated in any event, then this will return a null result.
return bestResult;
}
I hope that this makes sense and will help you think about things in a more OO way. This way you can define other methods for Event such as how to get the Participant with the highest Result.
Of course this is just one way to layout the classes, and I highly encourage you to try to think ahead of time how you want your objects to interact with each other before coding. Think about relationships between objects. I know you are just a beginner, so this might be a little advanced, but if you are serious about learning how to code efficiently, this is definitely something to look into.
Resultinstead of double and then return the winning object. To store that object you can create a instance of an object in your method.return Collections.max(eventResults, Comparator.comparingDouble(Result::getResult));