Just a few of small things I noticed when looking at your final code - these will hopefully be of some use in the future. I've avoided new concepts you haven't learnt yet (like multi dimensional arrays or objects), so it should be simple enough to follow.
[1] You can write a loop to read in the contestant names. There is no reason to create contestant1, contestant2 and contestant3 as separate variables either - you already have them!
Code:
for(int i = 0; i < names.length; i++)
{
names[i] = console.next();
}
[2] The code to read in the scores and then calculate the min, max, average and total scores is duplicated for each contestant. What happens if you need to add a 4th contestant? More duplication!
Want to add 100 contestants? - you'll need a lot of coffee...
Again, another loop can be used:
Code:
String[] names= new String[3];
double[] finalScores = new double[3];
for(int i = 0; i < names.length; i++)
{
// code goes here
}
The only thing you need to keep a record of (outside the loop) is the name of each contestant, along with their final score. names[0] is the name of contestant one. finalScores[0] is the score for contestant one etc.
[3] When reading in the scores, you can keep a running record of the min, max and sum at the same time.
Code:
double[] score = new double[8];
double highestScore = 0;
double lowestScore = 0;
double sumOfScores = 0;
for(int j = 0; j < score.length; j++)
{
score[i] = console.nextDouble();
if(score[i] < lowestScore)
{
lowestScore = score[i];
}
if(score[i] > highestScore)
{
highestScore = score[i];
}
sumOfScores += score[i];
}
This means you only need calculate the average and final score after the scores have been entered as you already have the min, max and sum:
Code:
// calculate the average
double averageScore = (sumOfScores / score.length);
// calculate the total score
finalScores[i] = sumOfScores - highestScore - lowestScore;
[4] Finally the logic to determine the winner can be simplified by (you guessed it!) a loop. All you need do is loop through each score and keep a record of the highest (or if two or more scores match).
Code:
// determine the winner, or if there is a tie
String winner = "";
double winningScore = 0;
boolean tie = false;
for(int i = 0; i < finalScores.length; i++)
{
if(finalScores[i] > winningScore)
{
// we have a new winning score
winningScore = finalScores[i];
winner = names[i];
tie = false;
}
else if(finalScores[i] == winningScore)
{
// score matches current best score
tie = true;
}
}
And then:
Code:
if(!tie)
{
System.out.println("The Winner of the gold medal is: " + winner);
}
else
{
System.out.println("There is a Tie!");
}