Convert the Baseball Team Manager program from procedural toobject-oriented. This shouldn?t change the functionality of thecode much,
Question:
Convert the Baseball Team Manager program from procedural toobject-oriented. This shouldn?t change the functionality of thecode much, but it should make the code more modular, reusable, andeasier to maintain.
Sample Console Output
- Use a Player class that provides attributes that store thefirst name, last name, position, at bats, and hits for a player.The class constructor should use these five attributes asparameters. This class should also provide a method that returnsthe full name of a player and a method that returns the battingaverage for a player.
- Use a Lineup class to store the lineup for the team as aprivate list. This class should include methods with appropriateparameters that allow youto add, remove, move,and get a player. The add method willadd a new player to the end of the list. The remove and get methodsrequire the lineup location of the targeted player. In addition, itmust include an iterator so that thelineup object can be used in a for loop.
- Use a file named ui to store thecode for the user interface.
- Use a file named objects to storethe code for the Player and Lineup classes.
- Use a file named db to store thefunctions that work with the file that stores the data. Use alineup object to hold the player objects that are created when thedata is read from the players.txt file.
- current code is to import a csv file I need it toimport a txt file
- sample txt info:
Dominick, Gilbert,1B,537,170Craig, Mitchell,CF,396,125Jack, Quinn,RF,345,99Simon, Harris,C,450,135Darryl, Moss,3B,501,120Grady, Guzman,SS,463,114Wallace, Cruz,LF,443,131Cedric, Cooper,2B,165,54Alberto, Gomez,P,72,19
def load_from_file(files, FILE_NAME):try:database = []inp = open(FILE_NAME , "r")line = inp.readline()except FileNotFoundError:print ("ERROR - Unable to open {}".format(FILE_NAME))quit()while(line):player = line.strip().split(",") if(len(player) == 4):valid = files.valid_POS(player[1])allow = Trueif(not valid):if(allow):print("Error(s) Occured in Player with details:",line)print("Position is Invalid")allow = Falsevalid = files.valid_at_bats(player[2])if(not valid):if(allow):print("Error(s) Occured in Player with details:",line)print("At bat is Invalid")allow = Falsevalid = files.valid_H(player[3])if(not valid):if(allow):print("Error(s) Occured in Player with details:",line)print("Invalid Hits")allow = Falsevalid = files.valid_AVG(player[3])if(allow):database.append(player)else:print("Invalid text:",line)line = inp.readline()inp.close()return database
def save_to_file(files, FILE_NAME, database):try:output = open(FILE_NAME , "w", encoding = "utf-8")except FileNotFoundError:print ("ERROR - Unable to open {}".format(FILE_NAME))quit()for data in database:data = ','.join(list(map(str, data)))print(data, file = output)
output.close()
Python project:
Project Management The Managerial Process
ISBN: 9781260570434
8th Edition
Authors: Eric W Larson, Clifford F. Gray