Question: For this assignment, you will write a program that simulates a tennis match. To win a match, the players play until one oftheln wins two

 For this assignment, you will write a program that simulates atennis match. To win a match, the players play until one ofthelnwins two or three sets [two for women's singles, three for men'ssingles]. To win a set, a player must win at least 6

For this assignment, you will write a program that simulates a tennis match. To win a match, the players play until one oftheln wins two or three sets [two for women's singles, three for men's singles]. To win a set, a player must win at least 6 games and must win two more games than the other player. For example, if player 1 wins a 6th game and player 2 has only won 4 games, player 1 has won the set. However if player 1 wins a 6th game and player 2 has won 5 games, the set must continue until one player has won at least 2 more games than the other. Between games, players alternate who serves the ball. You will need to create a class called TennisMatch that keeps track of all ofthe data needed to simulate a tennis match. In addition you must create a main class called YourlastnameAssignE . j ava [with your actual last name] that uses the TennisMatch class to run simulations until the user wants to stop. The TennisMatch class should have private elds representing the following values: 0 The number of sets required to win a match. 0 The probability that player 1 wins a game when serving. The probability that player 2 wins a game when serving. . Which player is currently serving. The number of games in the current set that player 1 has won. The number of games in the current set that player 2 has won. The number of sets in the match that player 1 has won. The number of sets in the match that player 2 has won. A string used to keep track of the results of each set. There should be one constructor for the TennisMatch that three arguments, one to initialize each of the three first fields listed above. It should initialize the remaining fields as follows: The initial server should be player 1. The number of games and sets won by each player should initially be zero. The string representing the results should initially be "" The class should contain one public method called playMatch that does the following: . Repeatedly plays a set (using the playset method) until a player has won the match (determined using the matchover method.) Displays the winner of the match along with the results of each set.You will also need to write the following private methods: private void playset ( ) does the following: Resets the number of games won for each player to zero. Repeatedly plays a game (using the playGame method) until a player has won the set (determined using the setover method.) Increments the number of sets won for whichever player won the game. Adds the results of the set to the string field described above. For example, if player 1 won 3 games and player 2 won 6 games, results of the set are summarized as 3-6. private void playGame ( ) does the following: Uses Math. random( ) to generate a random number between 0 and 1. Compare the random number to the current server's win probability. If the number is less than or equal to that probability, the server won the game. Otherwise, the server's opponent has won the game.'- Increment the number of games won by whoever won the game. '- Switch the current server. private boolean matchver() returns true if one of the players has won the required number ofsets to win, and False otherwise. private boolean setOver() returns true ifone of the players has won at least 6 games and that player has won 2 more games than their opponent. Example Input and Output Here is an example run of the program [note that the numbers may vary as you are using a random number generator]: welcome to Nicholas Coleman's tennis match simulator Please enter the number of sets needed to win a match: 3 Please enter the probability of player 1 winning: 8.5 Please enter the probability at player 2 winning: 9.6 Player 1 wins: 64 45 5? ?3 ?5 would you like to run another simulation? (YIN): Y Please enter the number of sets needed to win a match: 2 Please enter the probability of player 1 winning: 3.?5 Please enter the probability at player 2 winning: 9.5 Player 1 wins: 64 3? 64 would you like to run another simulation? (YIN): N Thank you for using the tennis match simulatorl

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!