//main method static void Main(string[] args) { //Addition of hockey player Player hp1 = new HockeyPlayer(PlayerType.HockeyPlayer, myList.Count + 1, "Mitchell Marner", "Maple Leafs", 9, 5, 8); myList.Add(hp1); Player hp2 = new HockeyPlayer(PlayerType.HockeyPlayer, myList.Count + 1, "Conner McDavid", "Edmonton Oilers", 9, 5, 9); myList.Add(hp2); //Addition of Basketball Player Player b1 = new HockeyPlayer(PlayerType.BasketballPlayer, myList.Count + 1, "Kyle Lowry", "Raptors", 15, 18, 4); myList.Add(b1); Player b2 = new HockeyPlayer(PlayerType.BasketballPlayer, myList.Count + 1, "Avery Bradley", "Heat", 8, 16, 2); myList.Add(b2); //Addition of Baseball Player Player ba1 = new HockeyPlayer(PlayerType.BaseballPlayer, myList.Count + 1, "Alejandro Kirk", "Blue Jays", 9, 4, 1); myList.Add(ba1); Player ba2 = new HockeyPlayer(PlayerType.BaseballPlayer, myList.Count + 1, "Kyle Higashioka", "Yankees", 16, 7, 4); myList.Add(ba2); //calling of Input method for HomePage of assignment Input(); }
//EditingHockeyPlayer method public static void EditingHockeyPlayer() { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine($"{"Player Type",-20} {"Player Id",10} {"Player Name",-20} {"Team name",-20} {"Games Played",20} {"Assists",20} {"Goals",20} {"Points",20}\n"); foreach (var i in myList) { if (i.PlayerType == PlayerType.HockeyPlayer) { Console.WriteLine(i); } } Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\nEditing Hockey Player\n"); Console.WriteLine("Enter ID of player you want to edit: "); int id; bool idIsNumeric = Int32.TryParse(Console.ReadLine(), out id); while (!idIsNumeric) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.WriteLine("Enter ID of player you want to edit: "); idIsNumeric = Int32.TryParse(Console.ReadLine(), out id); } if (id <= myList.Count && myList[id - 1].PlayerType == PlayerType.HockeyPlayer) { Console.Write("Enter Player's new name: "); string hockeyPlayer = Console.ReadLine(); while (string.IsNullOrWhiteSpace(hockeyPlayer)) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.Write("Enter Player's new name: "); hockeyPlayer = Console.ReadLine(); } Console.Write("Enter new Team name: "); string hockeyTeamname = Console.ReadLine(); while (string.IsNullOrWhiteSpace(hockeyTeamname)) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.Write("Enter new Team name: "); hockeyTeamname = Console.ReadLine(); } Console.Write("Enter Games Played: "); int hockeyGamePlayed; bool gamePlayedIsNumeric = Int32.TryParse(Console.ReadLine(), out hockeyGamePlayed); while (!gamePlayedIsNumeric) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.Write("Enter Games Played: "); gamePlayedIsNumeric = Int32.TryParse(Console.ReadLine(), out hockeyGamePlayed); } Console.Write("Enter Assists: "); int hockeyAssists; bool assistsIsNumeric = Int32.TryParse(Console.ReadLine(), out hockeyAssists); while (!assistsIsNumeric) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.Write("Enter Assists: "); assistsIsNumeric = Int32.TryParse(Console.ReadLine(), out hockeyAssists); } Console.Write("Enter Goals: "); int hockeyGoals; bool goalsIsNumeric = Int32.TryParse(Console.ReadLine(), out hockeyGoals); while (!goalsIsNumeric) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.Write("Enter Goals: "); goalsIsNumeric = Int32.TryParse(Console.ReadLine(), out hockeyGoals); } myList[id - 1] = new HockeyPlayer(PlayerType.HockeyPlayer, id, hockeyPlayer, hockeyTeamname, hockeyGamePlayed, hockeyAssists, hockeyGoals); Console.WriteLine("\nPlayer with ID = " + id + " updated\n"); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine($"{"Player Type",-20} {"Player Id",10} {"Player Name",-20} {"Team name",-20} {"Games Played",20} {"Assists",20} {"Goals",20} {"Points",20}\n"); foreach (var i in myList) { if (i.PlayerType == PlayerType.HockeyPlayer) { Console.WriteLine(i); } } } else { Console.WriteLine("Invalid Input! We dont have that id in Hockey Players Table"); EditingHockeyPlayer(); } Console.ReadKey(); Console.ForegroundColor = ConsoleColor.White; EditingPlayer(); }
//AddingHockeyPlayer method public static void AddingHockeyPlayer() { Console.WriteLine("\nAdding Hockey Player\n"); Console.Write("Enter Player name: "); string hockeyPlayer = Console.ReadLine(); while (string.IsNullOrWhiteSpace(hockeyPlayer)) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.Write("Enter Player name: "); hockeyPlayer = Console.ReadLine(); } Console.Write("Enter Team name: "); string hockeyTeamName = Console.ReadLine(); while (string.IsNullOrWhiteSpace(hockeyTeamName)) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.Write("Enter Team name: "); hockeyTeamName = Console.ReadLine(); } Console.Write("Enter Games Played: "); int hockeyGamePlayed; bool gamePlayedIsNumeric = Int32.TryParse(Console.ReadLine(), out hockeyGamePlayed); while (!gamePlayedIsNumeric) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.Write("Enter Games Played: "); gamePlayedIsNumeric = Int32.TryParse(Console.ReadLine(), out hockeyGamePlayed); } Console.Write("Enter Assists: "); int hockeyAssists; bool assistsIsNumeric = Int32.TryParse(Console.ReadLine(), out hockeyAssists); while (!assistsIsNumeric) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.Write("Enter Assists: "); assistsIsNumeric = Int32.TryParse(Console.ReadLine(), out hockeyAssists); } Console.Write("Enter Goals: "); int hockeyGoals; bool goalsIsNumeric = Int32.TryParse(Console.ReadLine(), out hockeyGoals); while (!goalsIsNumeric) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.Write("Enter Goals: "); goalsIsNumeric = Int32.TryParse(Console.ReadLine(), out hockeyGoals); } Player newHockePlayer = new HockeyPlayer(PlayerType.HockeyPlayer, myList.Count + 1, hockeyPlayer, hockeyTeamName, hockeyGamePlayed, hockeyAssists, hockeyGoals); myList.Add(newHockePlayer); Console.WriteLine("\nNew Player Added.\n\nView All HockeyPlayers: \n\n"); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine($"{"Player Type", -20} {"Player Id",10} {"Player Name",-20} {"Team name",-20} {"Games Played",20} {"Assists",20} {"Goals",20} {"Points",20}\n"); foreach (var i in myList) { if (i.PlayerType == PlayerType.HockeyPlayer) { Console.WriteLine(i); } } Console.ReadKey(); Console.ForegroundColor = ConsoleColor.White; AddingPlayer(); }