Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

image text in transcribed

image text in transcribedimage text in transcribed

image text in transcribed

image text in transcribedimage text in transcribed

image text in transcribedimage text in transcribed

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: " A 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 ite the method thatowing format: # 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 from team import Team from bench import Bench def main(): print("Welcome to the team manager.") # Here's where we create objects for the team and the bench. These # objects will be able to call the methods we've defined in their # respective classes. When the constructor functions are called here, # the classes' _init_() method is called with these values # passed to it. In both of these cases no arguments are passed, here. # However, the "self argument is always implicitly passed with any # method call. the_team = Team() the_bench = Bench) while True: # Immediately converting the input to lower() lets the user enter # any kind of capitalization, so it's a little less strict. command = (input("What do you want to do? ")).lower) if command == "done": print("Shutting down team manager ") return # this return statement exits main, ending the session. elif command == *set team name" : do_set_team_name(the_team) elif command == "show roster": do_show_team_roster(the_team) elif command == "add player": do_add_player_to_team(the_team) elif command == "check position is filled": _ do_check_position_filled(the_team) elif command == "send player to bench": do_send_player_to_bench(the_team, the_bench) elif command == "get player from bench": do_get_player_from_bench(the_bench) elif command == "cut player": # TODO: call a function that calls # the appropriate method on the team # object to cut the player (you need # to write the function below) pass elif command == "show bench": # TODO: call a function to call the necessary # bench method to show the names of the players # who are currently on the bench. pass else: do_not_understand) def do_set_team_name(team): name = input("What do you want to name the team? "); team.set_team_name(name)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions