static void Main(string[] args) { List <Staff> myStaff; FileReader fr = new FileReader(); int month = 0; int year = 0; while (year == 0) { Write("\nPlease enter the year: "); try { string userInput = ReadLine(); year = Convert.ToInt32(userInput); } catch (FormatException e) { WriteLine(e.Message); } } while (month == 0) { Write("\nPlease enter the month: "); try { string userInput = ReadLine(); month = Convert.ToInt32(userInput); if (month < 1 || month > 12) { WriteLine("Invalid month input"); month = 0; } } catch (FormatException e) { WriteLine(e.Message); } } myStaff = fr.ReadFile(); for (int i = 0; i < myStaff.Count; i++) { Staff employee = myStaff[i]; try { WriteLine($"Enter hours worked for {employee.NameOfStaff}"); employee.HoursWorked = Convert.ToInt32(ReadLine()); WriteLine(employee.HoursWorked); employee.CalculatePay(); WriteLine(employee); } catch (Exception e) { WriteLine(e.Message); i--; } } PaySlip ps = new PaySlip(month, year); ps.GeneratePaySlip(myStaff); ps.GenerateSummary(myStaff); Read(); }
public static void Main(string[] args) { //Polymorphism List <Staff> myStaff = new List <Staff>(); FileReader fr = new FileReader(); int month = 0; int year = 0; while (year == 0) { Console.Write("\nPlease enter the year: "); try { year = Convert.ToInt32(Console.ReadLine()); } catch (Exception e) { Console.WriteLine(e.Message + " Please try again."); } } while (month == 0) { Console.Write("\nPlease enter the month: "); try { month = Convert.ToInt32(Console.ReadLine()); if (month < 1 || month > 12) { Console.WriteLine("Month must be from 1 to 12. Please try again."); month = 0; } } catch (Exception e) { Console.WriteLine(e.Message + " Please try again."); } } myStaff = fr.ReadFile(); for (int i = 0; i < myStaff.Count; i++) { try { Console.Write("\nEnter hours worked for {0}: ", myStaff[i].NameOfStaff); myStaff[i].HoursWorked = Convert.ToInt32(Console.ReadLine()); myStaff[i].CalculatePay(); Console.WriteLine(myStaff[i].ToString()); } catch (Exception e) { Console.WriteLine(e.Message); i--; } } PaySlip ps = new PaySlip(month, year); ps.GeneratePaySlip(myStaff); ps.GenerateSummary(myStaff); Console.Read(); }