1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
12345 [234]
4 years ago
15

Design and implement a program to process golf scores. The scores of four golfers are stored in a text file (download golf.txt f

rom moodle). Each line represents one hole, and the file contains 18 lines. Each line contains five values: par for the hole followed by the number of strokes each golfer used on that hole.1) Store the totals for par and the players in an ArrayList.2) Determine the winner and produce a table showing how well each golfer did (compared to par).3) Modify the StyleOptions program in chapter 5 to allow the user to specify the size of the font. Use a text field to obtain the size
Computers and Technology
1 answer:
Phantasy [73]4 years ago
5 0

Answer:

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 !!

You might be interested in
Me Completan Pliiiis
Brut [27]
Can you translate please i’ll help better
4 0
3 years ago
What is the purpose of an internet protocol address (ip address)?
Karolina [17]
To provide the network number and node number of a machine. Not too useful without a network mask to separate them.
5 0
3 years ago
What is the name of the computer that access shared resources on the network<br><br>​
tangare [24]

Answer:

what is the name of the computer that access shared resources on the network

5 0
3 years ago
Read 2 more answers
What is the value of the variable named result after the following code executes?
Makovka662 [10]

Answer:

The value of result is 20

Explanation:

Given

The above code segment

Required

The value of result

In the first line, we have:

X = 5; Y = 3; Z = 2

In the second, we have:

result = (X + Y)/Z * X

This implies that:

result = (5 + 3)/2 * 5

result = 8/2 * 5

result = 4 * 5

result = 20

3 0
3 years ago
Assume that the classes listed in the Java Quick Reference have been imported where appropriate.
Georgia [21]

rcre2nvijrnv

u1bcihdebc

nn

8 0
4 years ago
Other questions:
  • Which button could Pamela press in the Microsoft Word spell checker to make the word “colour” instantly change to “color” whenev
    11·1 answer
  • A _____ is an area hosted by a Web server in which project members and colleagues can share documents, models, photos, and other
    6·1 answer
  • Methods used to change variables are called ______. equals accessors toString void mutators
    5·1 answer
  • Write qbasic code for given pattern<br><br>NEPAL<br>. EPA<br>. P​
    12·1 answer
  • To adjust the margins on a page, users will navigate to the _____ tab.
    13·2 answers
  • Which of the following statements about certificates is true?
    14·2 answers
  • What is the maximum duration of daily Scrum meetings?
    13·1 answer
  • The time delay of a long-distance call can be determined by multiplying a small fixed constant by the number of communication li
    8·1 answer
  • This is more a question for Brainly,
    5·2 answers
  • I NEED INFORMATION ON THE WALT DISNEY VS. FADEN CASE ASAP<br> WILL GIVE BRAINLIEST
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!