In [1]:
# We begin by liking the user interface to the Team class
from team import Team

# Defining the new class allowing us to add multiple teams, view, update, and delete teams
class HockeyTeamManager:
    def __init__(self):
        self.teams = []

# a loop that displays a menu of options to the user and performs the corresponding actions based on the user's input.
    def run(self):
        while True:
            self.print_menu()
            choice = input("Enter choice: ")
            if choice == "1":
                self.create_team()
            elif choice == "2":
                self.read_team()
            elif choice == "3":
                self.read_boys_teams()
            elif choice == "4":
                self.read_girls_teams()
            elif choice == "5":
                self.read_all_teams()
            elif choice == "6":
                self.update_team()
            elif choice == "7":
                self.delete_team()
            elif choice == "8":
                break
            else:
                print("Invalid choice. Please try again.")

# print_menu(self) - displays a menu of options to the user.
    def print_menu(self):
        print("---- Welcome to the Hockey Team Manager platform. Choose an option to continue ----")
        print("1. Create a new team")
        print("2. Read a specific team")
        print("3. Read all boys' teams")
        print("4. Read all girls' teams")
        print("5. Read all teams")
        print("6. Update a team")
        print("7. Delete a team")
        print("8. Exit")

# create_team(self) - prompts the user to enter the details of a new team,
    # creates a Team object with the entered details, and adds the team to the list of teams.

    def create_team(self):
        print("---- Create a new team ----")
        name = input("Enter team name: ")
        team_type = input("Enter team type (boys/girls): ")
        if team_type not in ["boys", "girls"]: # If statement to check whether the user entered only one of the required team types.
            print("Error: invalid team type. Enter either boys/girls") # Error message if team type is not valid
            return
        fee_paid_input = input("Has the fee been paid? (y/n): ")
        fee_paid = True if fee_paid_input.lower() == "y" else False
        fee = input("Enter fee amount: ")

        team = Team(name, team_type, fee_paid, fee)
        self.teams.append(team) # ensuring we can add new teams onto the existing list in the database
        print(f"Team {team.id} added successfully!") # success message displayed to the user

# read_team(self) - prompts the user to enter the ID of a team and displays the details of that team if it exists

    def read_team(self):
        print("---- Read a specific team ----")
        team_id = int(input("Enter team ID: "))
        for team in self.teams:
            if team.id == team_id:
                print(team)
                return
        print(f"No team with ID {team_id} found.") # error message if the ID entered does not exist

# read_boys_teams(self) - displays details of all boys' teams saved in the program
    def read_boys_teams(self):
        print("---- All Boys' Teams ----")
        for team in self.teams:
            if team.get_type() == "boys":
                print(team)

# read_girls_teams(self) - displays details of all girls' teams saved in the program
    def read_girls_teams(self):
        print("---- All Girls' Teams ----")
        for team in self.teams:
            if team.get_type() == "girls":
                print(team)

# read_all_teams(self) - displays the details of all the teams in the list of teams

    def read_all_teams(self):
        print("---- All Teams ----")
        for team in self.teams:
            print(team)

# update_team(self) - prompts the user to enter the ID of a team and the new details of the team,
    # updates the details of the team with the entered details if the team exists

    def update_team(self):
        print("---- Update a team ----")
        team_id = input("Enter team ID: ")
        team_index = self.find_team_index(team_id)
        if team_index is not None:
            team = self.teams[team_index]
            name = input("Enter new team name (leave blank to keep current name): ")
            if name != "":
                team.set_name(name)
            team_type = input("Enter new team type (boys/girls) (leave blank to keep current type): ")
            if team_type != "":
                team.set_type(team_type)
            fee_paid = input("Has the fee been paid? (y/n) (leave blank to keep current fee status): ")
            if fee_paid.lower() == "y":
                team.set_fee_paid(True)
            elif fee_paid.lower() == "n":
                team.set_fee_paid(False)
            fee = input("Enter new fee amount (leave blank to keep current fee amount): ")
            if fee != "":
                team.set_fee(float(fee))
            print("Team updated successfully.")
        else:
            print("Team {team_id} not found.")

    # helper method to find the index of the team with the given id in the teams list
    def find_team_index(self, team_id):
        for i in range(len(self.teams)):
            if str(self.teams[i].id) == team_id:
                return i
        return None

# delete_team(self) - prompts the user to enter the ID of a team and deletes the team with the entered ID if it exists

    def delete_team(self):
        print("---- Delete a team ----")
        team_id = int(input("Enter team ID: "))
        for i, team in enumerate(self.teams):
            if team.id == team_id:
                del self.teams[i]
                print(f"Team {team_id} deleted successfully.")
                return
        print(f"No team with ID {team_id} found.")

# Initiating the program by calling the "run" method
HockeyTeamManager().run()
---- Welcome to the Hockey Team Manager platform. Choose an option to continue ----
1. Create a new team
2. Read a specific team
3. Read all boys' teams
4. Read all girls' teams
5. Read all teams
6. Update a team
7. Delete a team
8. Exit
Enter choice: 1
---- Create a new team ----
Enter team name: Eagles
Enter team type (boys/girls): boys
Has the fee been paid? (y/n): y
Enter fee amount: 5000
Team 1 added successfully!
---- Welcome to the Hockey Team Manager platform. Choose an option to continue ----
1. Create a new team
2. Read a specific team
3. Read all boys' teams
4. Read all girls' teams
5. Read all teams
6. Update a team
7. Delete a team
8. Exit
Enter choice: 1
---- Create a new team ----
Enter team name: Falcons
Enter team type (boys/girls): girls
Has the fee been paid? (y/n): y
Enter fee amount: 5000
Team 2 added successfully!
---- Welcome to the Hockey Team Manager platform. Choose an option to continue ----
1. Create a new team
2. Read a specific team
3. Read all boys' teams
4. Read all girls' teams
5. Read all teams
6. Update a team
7. Delete a team
8. Exit
Enter choice: 1
---- Create a new team ----
Enter team name: lovers
Enter team type (boys/girls): boys
Has the fee been paid? (y/n): y
Enter fee amount: 5000
Team 3 added successfully!
---- Welcome to the Hockey Team Manager platform. Choose an option to continue ----
1. Create a new team
2. Read a specific team
3. Read all boys' teams
4. Read all girls' teams
5. Read all teams
6. Update a team
7. Delete a team
8. Exit
Enter choice: 1
---- Create a new team ----
Enter team name: Dragons
Enter team type (boys/girls): girls
Has the fee been paid? (y/n): n
Enter fee amount: 0
Team 4 added successfully!
---- Welcome to the Hockey Team Manager platform. Choose an option to continue ----
1. Create a new team
2. Read a specific team
3. Read all boys' teams
4. Read all girls' teams
5. Read all teams
6. Update a team
7. Delete a team
8. Exit
Enter choice: 2
---- Read a specific team ----
Enter team ID: 3
Team ID: 3
Date created: 2023-06-18
Team name: lovers
Team type: boys
Fee paid: True
Fee paid: 5000

---- Welcome to the Hockey Team Manager platform. Choose an option to continue ----
1. Create a new team
2. Read a specific team
3. Read all boys' teams
4. Read all girls' teams
5. Read all teams
6. Update a team
7. Delete a team
8. Exit
Enter choice: 3
---- All Boys' Teams ----
Team ID: 1
Date created: 2023-06-18
Team name: Eagles
Team type: boys
Fee paid: True
Fee paid: 5000

Team ID: 3
Date created: 2023-06-18
Team name: lovers
Team type: boys
Fee paid: True
Fee paid: 5000

---- Welcome to the Hockey Team Manager platform. Choose an option to continue ----
1. Create a new team
2. Read a specific team
3. Read all boys' teams
4. Read all girls' teams
5. Read all teams
6. Update a team
7. Delete a team
8. Exit
Enter choice: 5
---- All Teams ----
Team ID: 1
Date created: 2023-06-18
Team name: Eagles
Team type: boys
Fee paid: True
Fee paid: 5000

Team ID: 2
Date created: 2023-06-18
Team name: Falcons
Team type: girls
Fee paid: True
Fee paid: 5000

Team ID: 3
Date created: 2023-06-18
Team name: lovers
Team type: boys
Fee paid: True
Fee paid: 5000

Team ID: 4
Date created: 2023-06-18
Team name: Dragons
Team type: girls
Fee paid: False
Fee paid: 0

---- Welcome to the Hockey Team Manager platform. Choose an option to continue ----
1. Create a new team
2. Read a specific team
3. Read all boys' teams
4. Read all girls' teams
5. Read all teams
6. Update a team
7. Delete a team
8. Exit
Enter choice: 8