static void Main(string[] args) { string compTeam1 = "", compTeam2 = ""; try { compTeam1 = args[0]; compTeam2 = args[1]; } catch (Exception) { incorrectInput(); } NFL league = LoadData(); if (isTeam(compTeam1, league) && isTeam(compTeam2, league)) { Console.WriteLine("Predicting winner for " + compTeam1 + " vs " + compTeam2 + "..."); Predictor(compTeam1, compTeam2, league); Console.ReadLine(); } else { incorrectInput(); } }
static bool isTeam(string teamName, NFL league) { bool teamExists = false; foreach (Team name in league.allTeams) { if (name.teamName == teamName) { teamExists = true; } } return(teamExists); }
static void Predictor(string compTeam1, string compTeam2, NFL nflTeams) { decimal avgScore1 = 0; decimal avgAllowed1 = 0; decimal avgScore2 = 0; decimal avgAllowed2 = 0; foreach (Team teamItem in nflTeams.allTeams) { if (teamItem.teamName == compTeam1) { avgScore1 = teamItem.avgScore; avgAllowed1 = teamItem.avgAllowed; } else if (teamItem.teamName == compTeam2) { avgScore2 = teamItem.avgScore; avgAllowed2 = teamItem.avgAllowed; } } decimal avgScore1Adjusted = Math.Round(((avgScore1 + avgAllowed2) / 2), 1, MidpointRounding.AwayFromZero); decimal avgScore2Adjusted = Math.Round(((avgScore2 + avgAllowed1) / 2), 1, MidpointRounding.AwayFromZero); if (avgScore1Adjusted > avgScore2Adjusted) { Console.WriteLine(compTeam1 + " will win by a score of " + avgScore1Adjusted + " - " + avgScore2Adjusted); } else if (avgScore2Adjusted > avgScore1Adjusted) { Console.WriteLine(compTeam2 + " will win by a score of " + avgScore2Adjusted + " - " + avgScore1Adjusted); } else if (avgScore1Adjusted == avgScore2Adjusted) { Console.WriteLine("TIE! Both " + compTeam1 + " and " + compTeam2 + " will score " + avgScore1Adjusted); } }