[Solved] Needed Code Person Class Package Person Import Javautilrandom Public Abstract Class Person Q37176376


Needed code:
Person Class:
package person;
import java.util.Random;
public abstract class Person implements PrintData {
private Random r = new Random();
private int id = 0;
private double val = 0;
private int game = 0;
public Person(int i,int x) {
id = i;
game = x;
val = r.nextDouble();
}
public String toString() {
return ” Value ” + val;
}
// public abstract void printId();
// public abstract void printVal();
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;
}
}
Player Class:
package person;
public class Player extends Person {
private int playerId = 0;
public Player(int i,int num,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());
}
}
Staff Class:
package person;
public class Staff extends Person {
private int staffId = 0;
public Staff(int i,int num,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());
}
}
Winner Class:
package game;
import java.util.Random;
import java.util.Scanner;
import person.*;
class Winner {
static int numRuns = 2;
static int numPerson = 2;
private Random r = new Random();
public static void main(String[] args) {
Winner w = newWinner();
Person[] winnersArray= new Person[numRuns];
Person[] personArray =new Person[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();
}
}
Person find_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];
}
Person find_game_winner(Person[] pa) {
int id1 = 0, id2 = 0;
double val1 = 0, val2 = 0;
System.out.println(“GameWinners: “);
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];
}
}
PrintData Interface:
package person;
public interface PrintData {
public void printId();
public void printVal();
}
The new assignment is an extension to the three previous assignments. The goal is to add a GUI based on JavaFX to the “Multi-Game Winner” while also including exception handling. Assignment 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 each new game a new set of Player and Staff 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 ofpersonArray andwinnerArray, (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 IllegalArgumentException to manage any exceptions from non-numerical entries to set the size of the arrays in the GUI. The GUI 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 use the “official solution from Assignment 3 * B.1 Package “person” The person package contains the Person, Player, and Staff classes as described in Assignment 3 B.2 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 B.3 Package “gui” The gui package contains the GameGUI class where all JavaFX code is found. You may include multiple classes in this package B.4 Program Output The program output inside the TextArea of the GUI is similar to that of Assignment 3 <Person> Id <specificId> from Game <gameId Value <val where <gameId> corresponds to the game number starting from 0 <Person> corresponds to either Player or Staff <specificId> corresponds to either <playerId> or<staffId> type <specificTotal> corresponds to either <totalPlayerNum> or <totalStaffNum> <val> corresponds to a random value between 0 and 1 Sample output: Game: 0 Staff Id 1 from Game 0; Value 0.9413720497191768 Staff Id 2 from Game 0; Value 0.12675823219989202 Player Id 1 from Game 0; Value 0.09728762044279848 Staff Id 3 from Game 0; Value 0.1825126176110694 Game Winner is: Staff Id 1 from Game 0; Value 0.9413720497191768 Game: 1 Player Id 1 from Game 1; Value 0.3607839120647821 Staff Id 1 from Game 1; Value 0.764314784846852 Player Id 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 Id 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 Id 2 from Game 3; Value 0.7515432842214887 Game Winner is: Staff Id 2 from Game 3; Value 0.9346865563493605 Game Winners: Staff Id 1 from Game 0; Value 0.9413720497191768 Player Id 2 from Game 1; Value 0.8184547210782026 Player Id 2 from Game 2; Value 0.9341721291722334 Staff Id 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 new assignment is an extension to the three previous assignments. The goal is to add a GUI based on JavaFX to the “Multi-Game Winner” while also including exception handling. Assignment 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 each new game a new set of Player and Staff 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 ofpersonArray andwinnerArray, (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 IllegalArgumentException to manage any exceptions from non-numerical entries to set the size of the arrays in the GUI. The GUI 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 use the “official solution from Assignment 3 * B.1 Package “person” The person package contains the Person, Player, and Staff classes as described in Assignment 3
B.2 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 B.3 Package “gui” The gui package contains the GameGUI class where all JavaFX code is found. You may include multiple classes in this package B.4 Program Output The program output inside the TextArea of the GUI is similar to that of Assignment 3 Id from Game
Expert Answer
Answer to Needed code: Person Class: package person; import java.util.Random; public abstract class Person implements PrintData { … . . .
OR

