Question: that is 2 code of java package com.mycompany.assignment 3 ; class PlayerNode { private int playerID; private String playerName; private int stamina; private PlayerNode right;

that is 2 code of java
package com.mycompany.assignment3;
class PlayerNode {
private int playerID;
private String playerName;
private int stamina;
private PlayerNode right;
private PlayerNode left;
PlayerNode(int playerID, String playerName, int stamina){
this.playerID = playerID;
this.playerName = playerName;
this.stamina = stamina;
this.right = null;
this.left = null;
}
public int getPlayerID(){
return playerID;
}
public String getPlayerName(){
return playerName;
}
public int getStamina(){
return stamina;
}
public PlayerNode getRight(){
return right;
}
public PlayerNode getLeft(){
return left;
}
public void setPlayerID(int playerID){
this.playerID = playerID;
}
public void setPlayerName(String playerName){
this.playerName = playerName;
}
public void setStamina(int stamina){
this.stamina = stamina;
}
public void setRight(PlayerNode right){
this.right = right;
}
public void setLeft(PlayerNode left){
this.left = left;
}
}
and
package com.mycompany.assignment3;
public class GameTree {
private PlayerNode root;
public GameTree(){
this.root = null;
}
// Method to add a player to the game tree
public void addPlayer(int playerID, String playerName, int stamina){
root = insert(root, playerID, playerName, stamina);
}
// Method to insert a player recursively
private PlayerNode insert(PlayerNode node, int playerID, String playerName, int stamina){
if (node == null){
return new PlayerNode(playerID, playerName, stamina);
}
if (playerID < node.getPlayerID()){
node.setLeft(insert(node.getLeft(), playerID, playerName, stamina));
} else if (playerID > node.getPlayerID()){
node.setRight(insert(node.getRight(), playerID, playerName, stamina));
}
return node;
}
// Method to update player's stamina
public void updatePlayerStamina(int playerID, int stamina){
update(root, playerID, stamina);
}
// Method to update player's stamina recursively
private void update(PlayerNode node, int playerID, int stamina){
if (node == null){
return;
}
if (playerID < node.getPlayerID()){
update(node.getLeft(), playerID, stamina);
} else if (playerID > node.getPlayerID()){
update(node.getRight(), playerID, stamina);
} else {
node.setStamina(stamina);
}
}
// Method to delete a player from the game tree
public void deletePlayer(int playerID){
root = delete(root, playerID);
}
// Method to delete a player recursively
private PlayerNode delete(PlayerNode node, int playerID){
if (node == null){
return null;
}
if (playerID < node.getPlayerID()){
node.setLeft(delete(node.getLeft(), playerID));
} else if (playerID > node.getPlayerID()){
node.setRight(delete(node.getRight(), playerID));
} else {
// Case 1: No child or one child
if (node.getLeft()== null){
return node.getRight();
} else if (node.getRight()== null){
return node.getLeft();
}
// Case 2: Two children
node.setPlayerID(minValue(node.getRight()));
node.setRight(delete(node.getRight(), node.getPlayerID()));
}
return node;
}
// Method to find the minimum value in a subtree
private int minValue(PlayerNode node){
int minValue = node.getPlayerID();
while (node.getLeft()!= null){
minValue = node.getLeft().getPlayerID();
node = node.getLeft();
}
return minValue;
}
// Method to display all players' information
public void displayAllPlayersInfo(){
displayInOrder(root);
}
// Method to display players' information in order recursively
private void displayInOrder(PlayerNode node){
if (node != null){
displayInOrder(node.getLeft());
System.out.printf("%d\t\t%s\t\t%d%n", node.getPlayerID(), node.getPlayerName(), node.getStamina());
displayInOrder(node.getRight());
}
}
// Method to display player information by ID
public void displayPlayerByID(int playerID){
PlayerNode player = search(root, playerID);
if (player != null){
System.out.printf("Player with ID

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 Databases Questions!