Answer:
The code is given below and output is attached
Step-by-step explanation:
//Java code
import java.util.Scanner;
public class GolfTournament {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Please enter the number of players: ");
int size = input.nextInt();
if(size<=0)
{
System.out.println("goodbye ");
return;
}
String[] names = new String[size];
int[] score1 = new int[size];
int[] score2 = new int[size];
int [] combinedScores = new int[size];
for (int i = 0; i <size ; i++) {
System.out.println(" -------------------------Player "+(i+1)+"------------------------- ");
System.out.print("Please enter the Player Name: ");
names[i] = getName();
System.out.print("Please enter the day 1 score: ");
score1[i] = getScore();
System.out.print("Please enter the day 2 score: ");
score2[i] = getScore();
combinedScores[i] = score1[i]+score2[i];
}
System.out.println("------------------------------------------------Tournament Statistics-----------------------------------------");
System.out.println("PlayerID\t\tDay1 Score\t\t Day2 Score\t\tCombined Score");
for (int i = 0; i <size ; i++) {
System.out.println(String.format("%10s %15s %15s %15s",names[i],score1[i],score2[i],combinedScores[i]));
}
System.out.println("--------------------------------------------------------- Leader ----------------------------------------------------");
System.out.println(names[findMinIndex(combinedScores)]);
System.out.println(" ---------------------------------------Players Within 10 Strokes of Leader --------------------------------- ");
int index = findMinIndex(combinedScores);
int valueWithin10 = combinedScores[index]+10;
for (int i = 0; i < size; i++) {
if(combinedScores[i]>combinedScores[index] && combinedScores[i]<=valueWithin10)
System.out.println(names[i]);
}
System.out.println("--------------------------------------------------See Ya’ At the 19th Hole---------------------------------------");
}
private static int findMinIndex(int[] c)
{
int index =0;
for (int i = 0; i <c.length ; i++) {
if(c[index]>c[i])
{
index = i;
}
}
return index;
}
private static boolean validateRange(int score)
score>95)
return true;
else
return false;
private static String getName()
{
Scanner input = new Scanner(System.in);
return input.nextLine();
}
private static int getScore()
{
Scanner input = new Scanner(System.in);
int score = input.nextInt();
while (validateRange(score))
{
System.err.println("ERROR... Score is not valid...");
System.out.println("Enter score: ");
score = input.nextInt();
}
return score;
}
}