Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Your program should provide interaction as follows, looping until the user inputs the word done. The following interactive lines should be regarded as part of
Your program should provide interaction as follows, looping until the user inputs the word done. The following interactive lines should be regarded as part of a single session with the program. The program introduces itself and asks you what you want to do. The options are set team name , show roster, add player, cut player, check position is filled, send player to bench , get player from bench , show bench , and done. At the beginning of the session the team has no name and no players: Welcome to the team manager. What do you want to do? show roster The lineup for Anonymous Team is: The team currently has no players Any other command or mis-typed command will get the I didn't understand that command response. What do you want to do? show rooster I didn't understand that command When you ask to add a player, you should be prompted to input the player's name, then the player's number, then the player's position. Dodgeball positions include catcher, corner, sniper , and thrower. In the following lines, the user adds three players and gives the team a name. Note the output of the roster at the end of the exchange: What do you want to do? add player What's the player's name? Garcia What's Garcia's number? 15 What's Garcia's position? catcher Added Garcia to Anonymous Team What do you want to do? set team name What do you want to name the team? Seattle Scorpions What do you want to do? add player What's the player's name? Wiggins What's Wiggins's number? 55 What's Wiggins's position? corner Added Wiggins to Seattle Scorpions What do you want to do? add player What's the player's name? McCann What's McCann's number? 99 What's McCann's position? sniper Added McCann to Seattle Scorpions What do you want to do? show roster The lineup for Seattle Scorpions is: Garcia catcher 55 Wiggins corner McCann sniper 15 The user can check to see if we have at least one person playing at a given position, with the check position is filled command. What do you want to do? check position is filled What position are you checking for? thrower No, the thrower position is not filled The user can send an existing player to the sideline bench. The user can get a player from the bench. Whoever has been resting longest on the bench (i.e., whoever was sent to the bench earliest) will always be the first player returned from the bench. This is an example of a data structure called a queue. Queues operate on a first in/first out (FIFO) basis. When a player is benched, that player should still remain on the team roster, even while they are on the bench. What do you want to do? send player to bench Who do you want to send to the bench? McCann What do you want to do? send player to bench Who do you want to send to the bench? Garcia What do you want to do? show bench The bench currently includes: Garcia McCann What do you want to do? get player from bench Got McCann from bench What do you want to do? get player from bench Got Garcia from bench What do you want to do? get player from bench The bench is empty. It is also possible for the user to cut a player from the team. What do you want to do? cut player Who do you want to cut? McCann What do you want to do? show roster The lineup for Seattle Scorpions is: 15 Garcia catcher 55 Wiggins corner The behavior of the program if a player is cut while on the bench is unspecified, so you should design your program to handle this situation in a sensible way. For example, you might forbid cutting a benched player (and give a message saying that the player hasn't been cut for this reason) or you might allow the cut and make sure that the player is removed from the bench also. Your code should not behave in an unexpected way, for example by giving a runtime error or allowing a benched player to pop back onto the team after having been cut. The interactive session ends when the user inputs done. What do you want to do? done Shutting down team manager Starter code Download the starter code here. Read the code carefully. Some of the functionality has been implemented already, some of it has been partially implemented, and some of it is entirely up to you. The parts that have been implented are relevant to the work you will need to do, so pay close attention to how the existing code is working. In the starter directory you'll find four files. Three of these files, team.py , bench.py, and player.py are modules that define the classes Team, Bench , and player , respectively. Calling python team_manager.py on the command line from within the team_manager_starter directory should run the program without problems. If you run into trouble running the starter code, get some help. class Bench: **A class representing a sidelines bench""" def init__(self): # TODO: Initialize the bench object with whatever # attributes and values it will need pass def send_to_bench(self, player_name): # TODO: Put the player "onto the bench" pass def get_from_bench(self): # TODO: Return the name of the player who has # been on the bench longest. pass # TODO: Write the function that will display the # current list of players on the bench # TODO: Write any other methods that might be used # by the methods above. class Player: **TA class representing a dodgeball player*** # TODO: Write a constructor __init_0 method) that # will take the necessary values, set them to # the player object's attributes, and create the # new instance of player. Like all methods, its first # parameter must be "self". The remaining parameters should # receive whatever pieces of data are relevant to creating # a new Player object. pass from player import Player class Team: **"A class representing a dodgeball team*** # All methods in Python include arguments representing the object # itself. In the method definition, this is represented by the # self parameter. def __init__(self): self.name = "Anonymous Team" self.players = [] # Another example of self. The method call only passes one argument, # the 'name; value. But the method definition must always include the # self parameter. def set_team_name(self, name): # TODO: set the team name pass # Note again that 'self is the first parameter. def add_player(self, player_name, player_number, player_position): # TODO: call the player class constructor with the appropriate # values to create a new player object, then add that # player object to the team's players list. pass def cut_player(self, player_name): # TODO: Remove the player with the name player_name # from the players list. pass def is position_filled(self, position): # TODO: Write the method that checks whether # there is currently at least one player on the team # occupying the requested position pass # TODO: Write any necessary methods to support the methods # above, and write the method that will display (print to screen) # the full team roster in the following format: # # # # The lineup for Seattle Scorpions is: 15 Garcia catcher 55 Wiggins corner 99 McCann sniper def do_show_team_roster(team): # TODO: call the method on the team object that # displays the roster pass def do_check_position_filled(team): position - input("What position are you checking for? ") # TODO: call the method on the team object that determines # whether a given position has at least one player filling it, # then print the appropriate message: # "Yes, the", position, "position is filled # or # "No, the", position, "position is not filled pass def do_add_player_to_team(team): player_name = input("What's the player's name? ") player_number = input("What's " + player_name + "'s number? ") player_position - input ("What's " + player_name =s position? ") # TODO: call the method on team that creates a new player and # adds the player to the team. print("Added", player_name, "to", team.name) def do_send_player_to_bench(tean, bench): name = input("Who do you want to send to the bench? ") # TODO: make sure that the player is actually on the team first, # and then call a method on the bench object to place the player # "on the bench". If this is accomplished successfully, print # "Sent", name, "to bench." # otherwise print # name, "isn't on the team." pass def do_get_player_from_bench(bench): # TODO: get the best-rested player by name from the bench # (i.e. the player who has been on the bench longest). Print to # the screen the name of the player who was retrieved from the # bench. If the bench is empty, print to the screen that the # bench is empty. pass # TODO: write a function that calls the appropriate method on the team # object to cut the player # TODO: write a function to call the necessary method to show the # names of the players who are currently on the bench. Your program should provide interaction as follows, looping until the user inputs the word done. The following interactive lines should be regarded as part of a single session with the program. The program introduces itself and asks you what you want to do. The options are set team name , show roster, add player, cut player, check position is filled, send player to bench , get player from bench , show bench , and done. At the beginning of the session the team has no name and no players: Welcome to the team manager. What do you want to do? show roster The lineup for Anonymous Team is: The team currently has no players Any other command or mis-typed command will get the I didn't understand that command response. What do you want to do? show rooster I didn't understand that command When you ask to add a player, you should be prompted to input the player's name, then the player's number, then the player's position. Dodgeball positions include catcher, corner, sniper , and thrower. In the following lines, the user adds three players and gives the team a name. Note the output of the roster at the end of the exchange: What do you want to do? add player What's the player's name? Garcia What's Garcia's number? 15 What's Garcia's position? catcher Added Garcia to Anonymous Team What do you want to do? set team name What do you want to name the team? Seattle Scorpions What do you want to do? add player What's the player's name? Wiggins What's Wiggins's number? 55 What's Wiggins's position? corner Added Wiggins to Seattle Scorpions What do you want to do? add player What's the player's name? McCann What's McCann's number? 99 What's McCann's position? sniper Added McCann to Seattle Scorpions What do you want to do? show roster The lineup for Seattle Scorpions is: Garcia catcher 55 Wiggins corner McCann sniper 15 The user can check to see if we have at least one person playing at a given position, with the check position is filled command. What do you want to do? check position is filled What position are you checking for? thrower No, the thrower position is not filled The user can send an existing player to the sideline bench. The user can get a player from the bench. Whoever has been resting longest on the bench (i.e., whoever was sent to the bench earliest) will always be the first player returned from the bench. This is an example of a data structure called a queue. Queues operate on a first in/first out (FIFO) basis. When a player is benched, that player should still remain on the team roster, even while they are on the bench. What do you want to do? send player to bench Who do you want to send to the bench? McCann What do you want to do? send player to bench Who do you want to send to the bench? Garcia What do you want to do? show bench The bench currently includes: Garcia McCann What do you want to do? get player from bench Got McCann from bench What do you want to do? get player from bench Got Garcia from bench What do you want to do? get player from bench The bench is empty. It is also possible for the user to cut a player from the team. What do you want to do? cut player Who do you want to cut? McCann What do you want to do? show roster The lineup for Seattle Scorpions is: 15 Garcia catcher 55 Wiggins corner The behavior of the program if a player is cut while on the bench is unspecified, so you should design your program to handle this situation in a sensible way. For example, you might forbid cutting a benched player (and give a message saying that the player hasn't been cut for this reason) or you might allow the cut and make sure that the player is removed from the bench also. Your code should not behave in an unexpected way, for example by giving a runtime error or allowing a benched player to pop back onto the team after having been cut. The interactive session ends when the user inputs done. What do you want to do? done Shutting down team manager Starter code Download the starter code here. Read the code carefully. Some of the functionality has been implemented already, some of it has been partially implemented, and some of it is entirely up to you. The parts that have been implented are relevant to the work you will need to do, so pay close attention to how the existing code is working. In the starter directory you'll find four files. Three of these files, team.py , bench.py, and player.py are modules that define the classes Team, Bench , and player , respectively. Calling python team_manager.py on the command line from within the team_manager_starter directory should run the program without problems. If you run into trouble running the starter code, get some help. class Bench: **A class representing a sidelines bench""" def init__(self): # TODO: Initialize the bench object with whatever # attributes and values it will need pass def send_to_bench(self, player_name): # TODO: Put the player "onto the bench" pass def get_from_bench(self): # TODO: Return the name of the player who has # been on the bench longest. pass # TODO: Write the function that will display the # current list of players on the bench # TODO: Write any other methods that might be used # by the methods above. class Player: **TA class representing a dodgeball player*** # TODO: Write a constructor __init_0 method) that # will take the necessary values, set them to # the player object's attributes, and create the # new instance of player. Like all methods, its first # parameter must be "self". The remaining parameters should # receive whatever pieces of data are relevant to creating # a new Player object. pass from player import Player class Team: **"A class representing a dodgeball team*** # All methods in Python include arguments representing the object # itself. In the method definition, this is represented by the # self parameter. def __init__(self): self.name = "Anonymous Team" self.players = [] # Another example of self. The method call only passes one argument, # the 'name; value. But the method definition must always include the # self parameter. def set_team_name(self, name): # TODO: set the team name pass # Note again that 'self is the first parameter. def add_player(self, player_name, player_number, player_position): # TODO: call the player class constructor with the appropriate # values to create a new player object, then add that # player object to the team's players list. pass def cut_player(self, player_name): # TODO: Remove the player with the name player_name # from the players list. pass def is position_filled(self, position): # TODO: Write the method that checks whether # there is currently at least one player on the team # occupying the requested position pass # TODO: Write any necessary methods to support the methods # above, and write the method that will display (print to screen) # the full team roster in the following format: # # # # The lineup for Seattle Scorpions is: 15 Garcia catcher 55 Wiggins corner 99 McCann sniper def do_show_team_roster(team): # TODO: call the method on the team object that # displays the roster pass def do_check_position_filled(team): position - input("What position are you checking for? ") # TODO: call the method on the team object that determines # whether a given position has at least one player filling it, # then print the appropriate message: # "Yes, the", position, "position is filled # or # "No, the", position, "position is not filled pass def do_add_player_to_team(team): player_name = input("What's the player's name? ") player_number = input("What's " + player_name + "'s number? ") player_position - input ("What's " + player_name =s position? ") # TODO: call the method on team that creates a new player and # adds the player to the team. print("Added", player_name, "to", team.name) def do_send_player_to_bench(tean, bench): name = input("Who do you want to send to the bench? ") # TODO: make sure that the player is actually on the team first, # and then call a method on the bench object to place the player # "on the bench". If this is accomplished successfully, print # "Sent", name, "to bench." # otherwise print # name, "isn't on the team." pass def do_get_player_from_bench(bench): # TODO: get the best-rested player by name from the bench # (i.e. the player who has been on the bench longest). Print to # the screen the name of the player who was retrieved from the # bench. If the bench is empty, print to the screen that the # bench is empty. pass # TODO: write a function that calls the appropriate method on the team # object to cut the player # TODO: write a function to call the necessary method to show the # names of the players who are currently on the bench
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