Transcribed Text
Programming exercise
The goal of this exercise is to use some of the object oriented features of C++ or Java.
The program is to simulate a tennis tournament, for our purposes, takes a field of 8
players and plays a series of three rounds, eliminating half the players with each round -
ending with a single (winning) player.
Individual rounds operate as follows:
Randornly divide the remaining players into pairs.
Simulate a single game between each pair, using the scoring rules specified in
below.
The winners advance to the next round, the losers are eliminated.
The user should enter the names of the 8 players, then the program should simulate each
of the three rounds, printing the result of each game.
At the end of the tournament the program should print the name of the winner and the
name of the second place finisher.
Your software must include appropriate classes of object for both a player and a
tournament, but beyond that the design is at your discretion.
In addition, the simulation between any two players is as follows:
The score will start at 0/0, and will continue until someone wins the game.
It is assumed that either player one or player two will win a point on tachplay
A (pseudo) random number generator will be used to determine the results of each
play, with each player equally likely to win any given point.
After each play, the program should indicate which player won the point, the new
score, and which player is serving next.
The program should then pause until the user strikes a key to continue
play.
The player who won the previous point serves for the next point (randomly
determine the player to serve first in the game).
The score is determined as follows (scores displayed as server/receiver).
Previous
Server
Receiver
Score
wins point
wins point
0/0
15/0
0/15
0/15
15/15
0/30
0/30
15/30
0/40
0/40
15/40
game
15/0
30/0
15/15
15/15
30/15
15/30
15/30
30/30
15/40
15/40
30/40
game
30/0
40/0
30/15
30/15
40/15
30/30
30/30
40/30
30/40
30/40
deuce
game
40/0
game
40/15
40/15
game
40/30
40/30
game
deuce
deuce
advantage
advantage
advantage
game
deuce
These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction
of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice.
Unethical use is strictly forbidden.
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Collections;
import java.util.Random;
import java.lang.Math;
public class Homework4 {
public static String nextScore(String currentScore, int server)
{
String score = "";
switch(currentScore){
case "0/0":
score = (server == 1) ? "15/0" : "0/15";
break;
case "0/15":
score = (server == 1) ? "15/15" : "0/30";
break;
case "0/30":
score = (server == 1) ? "15/30" : "0/40";
break;
case "0/40":
score = (server == 1) ? "15/40" : "game";
break;
case "15/0":
score = (server == 1) ? "30/0" : "15/15";
break;
case "15/15":
score = (server == 1) ? "30/15" : "15/30";
break;
case "15/30":
score = (server == 1) ? "30/30" : "15/40";
break;
case "15/40":
score = (server == 1) ? "30/40" : "game";
break;
case "30/0":
score = (server == 1) ? "40/0" : "30/15";
break;
case "30/15":
score = (server == 1) ? "40/15" : "30/30";
break;
case "30/30":
score = (server == 1) ? "40/30" : "30/40";
break;
case "30/40":
score = (server == 1) ? "deuce" : "game";
break;
case "40/0":
score = (server == 1) ? "game" : "40/15";
break;
case "40/15":
score = (server == 1) ? "game" : "40/30";
break;
case "40/30":
score = (server == 1) ? "game" : "deuce";
break;
case "deuce":
score = (server == 1) ? "advantage" : "advantage";
break;
case "advantage":
score = (server == 1) ? "game" : "deuce";
break;
}
return score;
}...