Answer:
Step-by-step explanation:
import java.io.*;
import java.util.*;
public class GolfScores
{
// *************************************************************
// the purpose of this program is to read golf scores between
// four players and figure out the winner with the lowest score
// **************************************************************
public static void main(String[] args) throws FileNotFoundException
{
final int HOLES = 28, VALUES_PER_LINE = 4;
int hole = 0;
int parscores[] = new int[HOLES];
//declare a file object to handle the text file with scores
File file1 = new File("golfscore.txt");
int sum0=0;
int sum1=0;
int sum2=0;
int sum3=0;
int sum4=0;
Scanner scan = new Scanner(file1);
// total par and scores for all holes
int scores[][] = new int[HOLES][VALUES_PER_LINE];
//loop to store the contents of the file into arrays
while (scan.hasNext())
{
int index = 0;
parscores[hole] = scan.nextInt();
while (index < 4)
{
scores[hole][index] = scan.nextInt(); // values in a line
index++;
}
//
hole++;
}
for(int i=0;i<HOLES;i++)
{
sum0+=parscores[i];
}
int sumarray[]=new int[4];
//loop to calculate the total score of each player
for(int row=0;row<HOLES;row++)
{
sum1+=scores[row][0];
sum2+=scores[row][1];
sum3+=scores[row][2];
sum4+=scores[row][3];
}
System.out.println();
System.out.println("Par for the course"+sum0);
System.out.println("Player 1:"+sum1);
System.out.println("Player 2:"+sum2);
System.out.println("Player 3:"+sum3);
System.out.println("Player 4:"+sum4);
sumarray[0]=sum1;
sumarray[1]=sum2;
sumarray[2]=sum3;
sumarray[3]=sum4;
int min=sumarray[0];
//Loop to find out the minimum score
for(int j=0;j<4;j++)
{
if(sumarray[j]<min)
min=sumarray[j];
}
System.out.print("The winner is ");
//condition statement to determine the winner
if(min==sum1)
{
System.out.print("Player1");
}
else if(min==sum2)
{
System.out.print("Player2");
}
else if(min==sum3)
{
System.out.print("Player3");
}
else
{
System.out.print("Player4");
}
}
}
cheers i hope this helped !!