Program 4: Golf Simulation

Due Date and Submission Requirements

The goal of this lab is:

Background and Directions

In this assignment, you will write a program that simulates a game of golf between several players, which will use a priority queue to keep track of turns. In golf, players play through a series of holes, and each hole has a par value. The par represents the number of strokes (or turns) a golfer is expected to finish the hole. For example, if a hole is a Par 6, but it takes the golfer 8 turns to finish hole, their score for that hole is +2 (also called a "double bogey"). After every hole is finished, the player adds up their score for each hole to get their final score. In golf you want to complete each hole in the least amount of turns possible, so a score below zero is a good thing.

When you play golf with a group, the players typically take turns hitting their respective ball. The order in which players hit their balls is not necessarily FIFO. The turn order in golf is based on how far the players are from the hole. Once each players take their first shot, the next player up will be the one that is farthest from the hole. This order is repeated until each player finishes the hole.


We will be working with a slightly simplified version, where players are simply just trying to hit their ball past a certain marker, and players will also be very inconsistent with how far they hit the ball.

You will read in information from two different files.
players.txt- This will be a list of players in the game. For each player, you will need to keep track of their score for each hole. Your program should be able to handle any amount of player N where N is between 2 and 100.
holes.txt- This holds information about each hole in the golf course. Each golf hole has its par value, and the total distance (in yards). Your program should be able to handle any amount of golf holes N where N is between 1 and 18.

Your program needs to keep track of the order of player turns, which must use a priority queue. The "priority" of this queue is whoever is the farthest distance away from the finish point.

When it is their turn, a player will hit the ball a random distance between 50 and 200 yards (inclusive). After that, they are placed in the priority queue and will wait until their next turn. If they finish a hole, they should not be placed back into the priority queue until the next hole. Every N turns (where N is the number active players for the hole), your program should print out the current order of turns, and should have a waitkey before proceeding. Note that the order of these four turns may not stay this way. Suppose the next player hits it 50 yards. It's possible it will be their again right away because they are still the farthest from the hole.

Your program will need to keep track of each player's score for each hole. This could just be an Array in the Player class. When all the holes are complete, your program should print out their final scores. If they finished over par by X strokes, their final score should be "+X". If they finished under par by X strokes, their final score should be "-X".

Starting Code and Requirements

You will develop your solution from scratch. You will need to have a PriorityQueue class, that stores Player objects to keep track of turns. This priority queue should just use a linked list. Here are the input files you will use:

Commenting

You will need to include an adequate amount of comments in your code. At a bare minimum each method should have a brief comment explaining what the method does. Basic getters and setters don't need a comment.

Sample Output

When you run your program, it should follow a similar format to this screenshot. Your program should clearly display hole information, how far each player hits during their turn, the turn order ever 4 turns, and the final score when all holes are complete.

Optional Hints

Restrictions

You are not allowed to import java.util.PriorityQueue

Grading (100 points)

Criteria Points
Program reads information from players.txt and holes.txt 10
A priority queue is used, and the order of turns is correctly followed 20
Players hit a ball a random distance each time, and their distance from hole is correctly updated 10
Priority queue is printed every N turns 10
Program keeps track of how many turns it took to finish a hole 10
Program correctly loops for each hole 10
Program keeps track of each players score, and correctly prints out the finals scores 20
Your program contains an adequate amount of comments 10






program 4 solution