Menu

[Solved]Java Code Package Game Import Javautilrandom Import Person Class Winner Static Int Numruns Q37160056

---The goal is to add a GUI based on JavatX while also including exception handling. Description is as follows: A random size

Game: 2 Player Id 1 from Game 2; Value 0.5013968226832225 Staff Id 1 from Game 2: Value 0.9243218748286065 Staff Id 2 from Ga

—Java code:

package game;

import java.util.Random;

import person.*;

class Winner {

      static int numRuns =2;

      static int numPerson =2;

      private Random r = newRandom();

      public static voidmain(String[] args) {    

                 Winner w = new Winner();

                 Person[] winnersArray = newPerson[numRuns];

                 Person[] personArray = newPerson[numPerson];

                 for (int x=0;x<winnersArray.length; x++) {

                      System.out.println(“Game: ” + x);

                      w.init_game(personArray,x);

                      Person p = w.find_person_winner(personArray);

                      if (p!= null) {

                            System.out.println(“Game Winner is: “);

                            p.printVal();

                            winnersArray[x]=p;

                      }

                 }

                Person win = w.find_game_winner(winnersArray);

                if (win != null) {

                      System.out.println(“All Game Winner is: “);

                      win.printVal();

                }

      }

      void init_game(Person[]pa, int x) {

           double tmp = 0;

           int numPlayers = 0;

           int numStaff = 0;

           for (int i=0; i<pa.length; i++) {

                 tmp = r.nextDouble();

                 if (tmp <= 0.5) {

                       numPlayers++;

                       pa[i] = new Player(i,numPlayers,x);

                 }

                 else {

                       numStaff++;

                       pa[i] = new Staff(i,numStaff,x);

                 }

                 pa[i].printVal();

           }

      }

      Personfind_person_winner(Person[] pa) {

           int id1 = 0, id2 = 0;

           double val1 = 0, val2 = 0;

           for (int i=0; i<pa.length; i++) {

                 id1 = pa[i].getId();

                 val1 = pa[i].getVal();

                 if (val1 > val2) {

                       val2 = val1;

                       id2 = id1;

                 }

           }    

           return pa[id2];

      }

      Personfind_game_winner(Person[] pa) {

           int id1 = 0, id2 = 0;

           double val1 = 0, val2 = 0;

           System.out.println(“Game Winners: “);

           for (int i=0; i<pa.length; i++) {

                 id1 = i; // pa[i].getId();

                 val1 = pa[i].getVal();

                 pa[i].printVal();

                 if (val1 > val2) {

                       val2 = val1;

                       id2 = id1;

                 }

           }

           return pa[id2];

      }

}

package person;

import java.util.Random;

public abstract class Person implements PrintData{

      private Random r = newRandom();

      private int id =0;

      private double val =0;

      private int game =0;

      public Person(int i,intx) {

          id =i;

          game =x;

          val =r.nextDouble();

      }

      public String toString(){

          return” Value ” + val;

      }

      public void printId(){

           System.out.println(” Person Id ” + id);

      }

      public void printVal(){

           System.out.print(” Person Id ” + id + ” from Game ” + game +”;”);

           System.out.println(toString());

      }

      public int getId(){

           return id;

      }

      public double getVal(){

           return val;

      }

      public int getGame(){

           return game;

      }

}

package person;

public class Player extends Person {

      private int playerId =0;

      public Player(int i,intnum,int x) {

         super(i,x);

         playerId = num;

      }

      public void printId(){

           System.out.println(” Player Id ” + playerId);

      }

      public void printVal(){

           System.out.print(” Player Id ” + playerId + ” from Game ” +getGame() + “;”);

           System.out.println(toString());

      }

}

package person;

public interface PrintData {

      public voidprintId();

      public voidprintVal();

}

package person;

public class Staff extends Person {

      private int staffId =0;

      public Staff(int i,intnum,int x) {

         super(i,x);

         staffId = num;

      }

      public void printId(){

           System.out.println(” Staff Id ” + staffId);

      }

      public void printVal(){

           System.out.print(” Staff Id ” + staffId + ” from Game ” + getGame()+ “;”);

           System.out.println(toString());

      }

}

—The goal is to add a GUI based on JavatX while also including exception handling. Description is as follows: A random sized personArray that stores objects of type Person. The personArray contains a random number of Player and Staff whose specific numbers may vary between games. During cach new game a new set of Playcr and Staf objects need to be created and stored in the array A random sized winnersArray that stores objects of type Person storing every game winner. This array may be of different size than personArray .The system provides a winner per game, and then an overall winner for all games The GUI must include the following functionality: (1) a text entry with a button to input the arbitrary lengths of personArray and winnerArray, (2) a button or menu to initialize the game (calling init game), (3) a button or menu to play the game (calling find_person_winner and find game_winner), and (4) a “TextArea” (or similar) to display all Winners .The program must handle the egal Argumentxception to manage any exceptions from non-numerical entries to set the size of the arrays in the GUI The GLI should permit re-initializing and re-playing of the game multiple times .You may design the GUI as you wish as long as it works and contains all the specified functionality . You may usc the Java code below as a starting point Package person” The person package contains the Person, Player, and Staff classes as described in the code below —Package game” The game package contains the Winner class, containing (1) the init game method where an arbitrary number of Player and Staff objects get instantiated for each game played, (2) A method called find person_winner returning the Person winner after each game, and (3) the find_game_winner returning the winner of all games -Package “gui” The gui package contains the GameGUI class where all JavaFX code is found. You may include multiple classes in this package -Program Output The program output inside the “TextArea” of the GUI is similar to that of the code below <Person> ldくspecificid> from Game <gameld>, Valueくval> <gameld> corresponds to the game number starting from 0 <Person> corresponds to either Player or Staff <specificld> corresponds to either <playerld> or <staffld> type specificTotal> corresponds to either <totalPlayerNum> or <totalStaftNum> val coresponds to a random value between 0 and 1 —Sample output: Game: 0 Staff Id 1 from Game O; Value 0.9413720497191768 Staff Id 2 from Game 0: Value O.12675823219989202 Player ld 1 from Game 0; Value 0.09728762044279848 Staff ld 3 from Game 0; Value 0.1825126176110694 Game Winner is: Staff Id 1 from Game 0: Value 0.9413720497191768 ame Player Id 1 from Game I; Value 0.3607839120647821 Staff ld 1 from Game 1; Value 0.764314784846852 Player ld 2 from Game 1; Value 0.8184547210782026 Player Id 3 from Game 1; Value 0.26964508660881936 Game Winner is: Player Id 2 from Game 1; Value 0.8184547210782026 Game: 2 Player Id 1 from Game 2; Value 0.5013968226832225 Staff Id 1 from Game 2: Value 0.9243218748286065 Staff Id 2 from Game 2; Value 0.892060295283974 Player Id 2 from Game 2; Value 0.9341721291722334 Game Winner is: Player ld 2 from Game 2; Value 0.9341721291722334 Game: 3 Staff Id 1 from Game 3; Value 0.05318193196716425 Staff Id 2 from Game 3; Value 0.9346865563493605 Player Id 1 from Game 3; Value 0.742478514800904 Player ld 2 from Game 3; Value 0.7515432842214887 Game Winner is: Staff Id 2 from Game 3: Value 0.9346865563493605 Game Winners Staff Id I from Game 0: Value 0.9413720497191768 Player Id 2 from Game 1; Value 0.8184547210782026 Player ld 2 from Game 2; Value 0.9341721291722334 Staff ld 2 from Game 3; Value 0.9346865563493605 All Game Winner is: Staff Id 1 from Game 0; Value 0.9413720497191768 Show transcribed image text —The goal is to add a GUI based on JavatX while also including exception handling. Description is as follows: A random sized personArray that stores objects of type Person. The personArray contains a random number of Player and Staff whose specific numbers may vary between games. During cach new game a new set of Playcr and Staf objects need to be created and stored in the array A random sized winnersArray that stores objects of type Person storing every game winner. This array may be of different size than personArray .The system provides a winner per game, and then an overall winner for all games The GUI must include the following functionality: (1) a text entry with a button to input the arbitrary lengths of personArray and winnerArray, (2) a button or menu to initialize the game (calling init game), (3) a button or menu to play the game (calling find_person_winner and find game_winner), and (4) a “TextArea” (or similar) to display all Winners .The program must handle the egal Argumentxception to manage any exceptions from non-numerical entries to set the size of the arrays in the GUI The GLI should permit re-initializing and re-playing of the game multiple times .You may design the GUI as you wish as long as it works and contains all the specified functionality . You may usc the Java code below as a starting point Package person” The person package contains the Person, Player, and Staff classes as described in the code below —Package game” The game package contains the Winner class, containing (1) the init game method where an arbitrary number of Player and Staff objects get instantiated for each game played, (2) A method called find person_winner returning the Person winner after each game, and (3) the find_game_winner returning the winner of all games -Package “gui” The gui package contains the GameGUI class where all JavaFX code is found. You may include multiple classes in this package -Program Output The program output inside the “TextArea” of the GUI is similar to that of the code below ldくspecificid> from Game , Valueくval> corresponds to the game number starting from 0 corresponds to either Player or Staff corresponds to either or type specificTotal> corresponds to either or val coresponds to a random value between 0 and 1 —Sample output: Game: 0 Staff Id 1 from Game O; Value 0.9413720497191768 Staff Id 2 from Game 0: Value O.12675823219989202 Player ld 1 from Game 0; Value 0.09728762044279848 Staff ld 3 from Game 0; Value 0.1825126176110694 Game Winner is: Staff Id 1 from Game 0: Value 0.9413720497191768 ame Player Id 1 from Game I; Value 0.3607839120647821 Staff ld 1 from Game 1; Value 0.764314784846852 Player ld 2 from Game 1; Value 0.8184547210782026 Player Id 3 from Game 1; Value 0.26964508660881936 Game Winner is: Player Id 2 from Game 1; Value 0.8184547210782026
Game: 2 Player Id 1 from Game 2; Value 0.5013968226832225 Staff Id 1 from Game 2: Value 0.9243218748286065 Staff Id 2 from Game 2; Value 0.892060295283974 Player Id 2 from Game 2; Value 0.9341721291722334 Game Winner is: Player ld 2 from Game 2; Value 0.9341721291722334 Game: 3 Staff Id 1 from Game 3; Value 0.05318193196716425 Staff Id 2 from Game 3; Value 0.9346865563493605 Player Id 1 from Game 3; Value 0.742478514800904 Player ld 2 from Game 3; Value 0.7515432842214887 Game Winner is: Staff Id 2 from Game 3: Value 0.9346865563493605 Game Winners Staff Id I from Game 0: Value 0.9413720497191768 Player Id 2 from Game 1; Value 0.8184547210782026 Player ld 2 from Game 2; Value 0.9341721291722334 Staff ld 2 from Game 3; Value 0.9346865563493605 All Game Winner is: Staff Id 1 from Game 0; Value 0.9413720497191768

Expert Answer


Answer to —Java code: package game; import java.util.Random; import person.*; class Winner { static int numRuns = 2; static int … . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *