Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IN JAVA:(please let me know if you need more info) The program is to simulate a

ID: 665420 • Letter: I

Question

IN JAVA:(please let me know if you need more info)

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 Randomly divide the remaining players into pairs. Simulate a single game between each pair, using the scoring rules specified in assignment 1 . 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 each play 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). See http://tennis.about.com/cs/beginners/a/beginnerscore.htm . Previous Score 0/0 0/15 0/30 Server wins point 15/0 15/15 15/30 Receiver wins point 0/15 0/30 0/40

Explanation / Answer

import System;
import System.Data;
import System.Configuration;
import System.Web;
import System.Web.Security;
import System.Web.UI;
import System.Web.UI.WebControls;
import System.Web.UI.WebControls.WebParts;
import System.Web.UI.HtmlControls;

{
    /// <summary>
    /// Summary description for TennisTournament
    /// </summary>
    public class TennisTournament
    {
        public TennisTournament()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public static double triangular(double Min,double Mode,double Max)
        {                      
            //   Declarations      
                 double R=0.0;                                 
            //   Initialise   
            Random r = new Random();
             R = r.NextDouble();          
            //    Triangular                      
            if ( R == (( Mode - Min) / ( Max - Min))) {
              return Mode;
            }
            else if ( R < (( Mode - Min) / ( Max - Min))) {
                return Min + Math.Sqrt( R * ( Max - Min) * ( Mode - Min));
            }
            else {
              return Max - Math.Sqrt((1 - R) * ( Max - Min) * ( Max - Mode));
            }
        }
        public static double[] simulate(int Total, double[] Tmin, double[] Tmod, double[] Tmax)
        {
            // Declarations
                int mlngEvals=10000;
               int i=0, i1=0, i2=0;           
               double[]   TMin = new double[Total];
               double[] TMod = new double[Total];
               double[] TMax = new double[Total];
               double[] mlngResults = new double[Total];
               double Time=0.0;
               long lngWinner=0;
               double Winner=0;             
            // Initialise          
                 for (i=0; i<Total; i++) {               
            //     distribution parameters
                    TMin[i]=Tmin[i];
                    TMod[i]=Tmod[i];
                    TMax[i]=Tmax[i];            
            //     Results Array            
                   mlngResults[i]=0;
                 }
            // The Tournament         
                 for (i1=1; i1<=mlngEvals; i1++) {       
            //     Seed             
                   lngWinner = 0;
                    Winner = triangular( TMin[0], TMod[0], TMax[0]);
            //     And the Rest
                     for (i2=1; i2<Total; i2++) {
                        Time = triangular( TMin[i2], TMod[i2], TMax[i2]);
                         if ( Time < Winner) {
                            Winner = Time;
                           lngWinner = i2;
                         }
                     }
            //     Bin
                   mlngResults[lngWinner]++;
               }
               return mlngResults;
        }
    }
}