Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Objective The primary objective of this program is to learn to implement binary search trees and to combine their functionalities with linked lists. Program Description
Objective
The primary objective of this program is to learn to implement binary search trees and to
combine their functionalities with linked lists.
Program Description
In a multiplayer game, players' avatars are placed in a large game scene, and each avatar
has its information in the game. Write a program to manage players' information in a
multiplayer game using a Binary Search BS tree for a multiplayer game. A node in the BS
tree represents each player. Each player should have an ID number, avatar name, and stamina
level. The players will be arranged in the BS tree based on their ID numbers. If there is only
one player in the game scene, it is represented by one node root in the tree. Once another
player enters the game scene, a new node will be created and inserted in the BS tree based on
the player ID number. Players during the gameplay will receive hits that reduce their stamina.
If the players lose all their stamina, they vanish from the game, and they should be deleted
from the tree. You are required to write the following methods:
Write a function to add a new player by adding a new node to the tree.
Write a function to search for a specific player by their ID
Write a function that prints all the players' names with their specified IDs and stamina
levels.
Write a function that prints the number of players that existed in the game.
Write a function that updates the stamina level for a specific player when they receive
hits from another player.
Write a function that removes a particular player from the game by removing their
node from the tree.
The program deals with three files. Two input files and one output file. The description of these
files is as follow:
o The first input file intialInformationtxt contains the important information for the
program which includes the number of players, the IDs, and the name for each player.
o The information in this file is arranged as follow:
o The first line contains the number of players.
o The following lines contain the players IDs and names.
o The commands for the system are found in the second file called commands.txt The
commands in this file are as follow:
o STARTUP: This command will use the first input file intialInformationtxt
to generate the BS tree by creating a node for each player in the tree.
o ADDPLAYER: This command has two values that represent the player ID
and the players name who entered the game scene. The command will create a
node in the tree that represents that player in the game. The default value for the
stamina level will be
o DISPLAYPLAYERINFO: This command has one value which is the player
ID It will output the name and the stamina level for the specified player. If the
specified player is not found, it will output the Not found any player with ID
number message.
o DISPLAYALLPLAYERS: This command will output all the players in the
game scene with the players IDs, names and stamina levels. Similar to the
output in the ouptput.txt file
o NUMOFPLAYERS: This command will print the total number of players
in the game scene.
o UPDATEPLAYERINFO: This command has one value which is the
player ID It will decrease the stamina level for the specified player by and it
will output the player received a hit and the stamina level
reduced by message. If the stamina level for the specified player reaches
zero, then the player will be removed from the game, and it will output the
The stamina level for the player reaches zero and left
the game! message. If the specified player is not found, it will output the
Not found any player with ID number message.
o DELETEPLAYER: This command has one value that represents the
players ID who will leave the game. The command will search for this player
in the tree then remove their node from the BS tree, and it will output the The
player left the game message. If the specified player is not found it
will output the Not found any player with ID number message.
o QUIT: This command will stop the program.
o The output of the program should be written to the file name it output.txt which content
should be similar to the contents of the file provided to you.
write it in java code
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started