private static List <TimeSheetEntryModel> LoadTimeSheets() { List <TimeSheetEntryModel> output = new List <TimeSheetEntryModel>(); string enterMoreTimeSheets = ""; do { Console.Write("Enter what you did: "); string workDone = Console.ReadLine(); Console.WriteLine(); Console.Write("How long did you do it for: "); string rawHoursWorked = Console.ReadLine(); Console.WriteLine(); double hoursWorked; while (double.TryParse(rawHoursWorked, out hoursWorked) == false) { Console.WriteLine("Invalid number given"); Console.WriteLine(); Console.Write("How long did you do it for: "); rawHoursWorked = Console.ReadLine(); Console.WriteLine(); } TimeSheetEntryModel timeSheet = new TimeSheetEntryModel(); timeSheet.HoursWorked = hoursWorked; timeSheet.WorkDone = workDone; output.Add(timeSheet); Console.Write("Do you want to enter more time (yes/no): "); enterMoreTimeSheets = Console.ReadLine(); Console.WriteLine(); } while (enterMoreTimeSheets == "yes"); return(output); }
static List <TimeSheetEntryModel> GetTimeSheetEntries() { List <TimeSheetEntryModel> timeSheetEntries = new List <TimeSheetEntryModel>(); bool continueEntering; do { Console.Write("Enter what you did: "); string workDone = Console.ReadLine(); Console.Write("How long did you do it for (in hours): "); int hoursDone = int.Parse(Console.ReadLine()); TimeSheetEntryModel entry = new TimeSheetEntryModel { HoursWorked = hoursDone, WorkDone = workDone }; timeSheetEntries.Add(entry); Console.Write("Do you want to enter more time (yes/no):"); continueEntering = Console.ReadLine().Equals("yes", StringComparison.OrdinalIgnoreCase); }while (continueEntering == true); return(timeSheetEntries); }
private static List <TimeSheetEntryModel> LoadTimeSheets() { bool extraTimeWorked = false; double hoursWorked; List <TimeSheetEntryModel> output = new List <TimeSheetEntryModel>(); do { Console.Write("Enter what you did: "); string input = Console.ReadLine(); Console.Write("How long did you do it for: "); string rawTimeWorked = Console.ReadLine(); while (double.TryParse(rawTimeWorked, out hoursWorked) == false) { Console.WriteLine(); Console.WriteLine("Invalid number given"); Console.Write("How long did you do it for: "); rawTimeWorked = Console.ReadLine(); } TimeSheetEntryModel entry = new TimeSheetEntryModel(); entry.HoursWorked = hoursWorked; entry.WorkDone = input; output.Add(entry); Console.Write("Do you want to enter more time (yes/no): "); string answer = Console.ReadLine(); extraTimeWorked = false; if (answer.ToLower() == "yes") { extraTimeWorked = true; } } while (extraTimeWorked == true); Console.WriteLine(); return(output); }
static void Main(string[] args) { string workDone; int hourDone; int timeTotal; List <TimeSheetEntryModel> timeSheetEntries = new List <TimeSheetEntryModel>(); List <CustomerModel> customer = new List <CustomerModel> { new CustomerModel { Name = "Acme", HourlyRate = 150 }, new CustomerModel { Name = "ABC", HourlyRate = 125 } }; bool continueEntering; do { Console.Write("Enter what you did: "); workDone = Console.ReadLine(); Console.Write("How long did you do it for(in hours): "); hourDone = int.Parse(Console.ReadLine()); TimeSheetEntryModel entry = new TimeSheetEntryModel { HoursWorked = hourDone, WorkDone = workDone }; timeSheetEntries.Add(entry); Console.Write("Do you want to enter more time:"); continueEntering = Console.ReadLine().ToLower() == "yes"; //continueEntering = Console.ReadLine().Equals("yes", StringComparison.OrdinalIgnoreCase); }while (continueEntering == true); timeTotal = TimeSheetProcessor.CalculateTimeForCustomer(timeSheetEntries, "Acme"); Console.WriteLine("Simulating Sending email to Acme"); Console.WriteLine("Your bill is $" + timeTotal * 150 + " for the hours worked."); timeTotal = TimeSheetProcessor.CalculateTimeForCustomer(timeSheetEntries, "ABC"); Console.WriteLine("Simulating Sending email to ABC"); Console.WriteLine("Your bill is $" + timeTotal * 125 + " for the hours worked."); for (int i = 0; i < timeSheetEntries.Count; i++) { timeTotal += timeSheetEntries[i].HoursWorked; } if (timeTotal > 40) { Console.WriteLine("You will get paid $" + timeTotal * 15 + " for your work."); } else { Console.WriteLine("You will get paid $" + timeTotal * 10 + " for your time."); } Console.WriteLine(); Console.Write("Press any key to exit application..."); Console.ReadKey(); }