/// <summary> /// Main method for calling welcome message and checking employee presence. /// </summary> /// <param name="args"></param> static void Main(string[] args) { NLog nLog = new NLog(); Console.WriteLine("Welcome to Employee Wage computation Program"); nLog.LogInfo("Welcome message displayed : Main()"); string checkForInput = "y"; ComputeEmployeeWage computeEmployeeWage = new ComputeEmployeeWage(); //instatiating computeEmployeewage class class for calling calculatemonthlywage method to calculate monthlywage. while (checkForInput.ToLower() == "y") { Console.WriteLine("Please enter the name of company"); string nameOfCompany = Console.ReadLine(); Console.WriteLine("Please enter wage per hour for company"); int wagePerHour = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Please enter no. of working days for company"); int noOfWorkingDays = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Please enter no. of working hours for month"); int monthlyWorkingHours = Convert.ToInt32(Console.ReadLine()); computeEmployeeWage.AddContactDetails(nameOfCompany, wagePerHour, noOfWorkingDays, monthlyWorkingHours); Console.WriteLine("Do you want to compute for another company, press y to compute."); checkForInput = Console.ReadLine(); } computeEmployeeWage.CalculateMonthlyWage(); computeEmployeeWage.toString(); }
/// <summary> /// calculating monthly wages provides index to array and tranfer values to private monthly method which computes monthly wages and returns it. /// </summary> public void CalculateMonthlyWage() { ComputeEmployeeWage computeEmployeeWage = new ComputeEmployeeWage(); //for(int a=0;a<companyIndex;a++) foreach (EmployeeDetails employeeDetails in employeeDetailsList) { int monthlyWage = computeEmployeeWage.CalculateMonthlyWage(employeeDetails); employeeDetails.SetTotalWage(monthlyWage); CompanyWageInDictionary.Add(employeeDetails.companyName, employeeDetails); } }
/// <summary> /// /// </summary> /// <param name="employeeDetail"></param> /// <returns></returns> internal int CalculateMonthlyWage(EmployeeDetails employeeDetail) { //Array for daily working hours and daily wages of workers int[] fullDayHour = new int[employeeDetail.noOfWorkingDays]; int workDayCount = 0; int totalWorkingHours = 0; int[] totalDailyWage = new int[employeeDetail.noOfWorkingDays]; int monthlyWage; Console.WriteLine($"Employee wages for {employeeDetail.companyName}"); //calculating total monthly wage by applying while loop on working days while (workDayCount < employeeDetail.noOfWorkingDays && totalWorkingHours <= employeeDetail.hoursPerMonth) { //using Random method to generate random no and compare with constants to check presence. Random random = new Random(); int checkIfPresent = random.Next(0, 3); // instatiating compute employee wage class and calling WorkHours method which returns no of hours according to employee's presence. ComputeEmployeeWage computeEmployeeWage = new ComputeEmployeeWage(); fullDayHour[workDayCount] = computeEmployeeWage.WorkHours(checkIfPresent, workDayCount); if (totalWorkingHours + fullDayHour[workDayCount] > employeeDetail.hoursPerMonth) { fullDayHour[workDayCount] = 0; } totalWorkingHours += fullDayHour[workDayCount]; totalDailyWage[workDayCount] = fullDayHour[workDayCount] * employeeDetail.wagePerHour; Console.WriteLine($"Total daily wage is for {workDayCount + 1} is {totalDailyWage[workDayCount]}"); workDayCount++; //.LogDebug("Successfully Calculated daily employee wage : Main()"); } monthlyWage = totalWorkingHours * employeeDetail.wagePerHour; nLog.LogDebug("Successfully calculated monthly employee wage: calculateMonthlyWage()"); Console.WriteLine("********************************************************************"); Console.WriteLine($"The monthly wage for employee of {employeeDetail.companyName} is {monthlyWage}"); return(monthlyWage); }