public void DefineSalaryExecute() { if (String.IsNullOrEmpty(Addition.ToString()) || Addition == 0) { MessageBox.Show("Please fill field for addition.", "Notification"); } else { try { if (Employee != null) { MessageBoxResult result = MessageBox.Show("Are you sure you want to define salary?", "Confirmation", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { Employee.Salary = CalculateSalary.CalculateForOne(Manager, Employee, Addition); bool isDefine = employees.SetSalary(Employee); if (isDefine == true) { MessageBox.Show("Salary is defined.", "Notification", MessageBoxButton.OK); EmployeeList = managers.GetEmployees(Manager); } else { MessageBox.Show("Salary cannot be defined.", "Notification", MessageBoxButton.OK); } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
private static void mv_Payment() { CalculateSalary c_CalcSalary = new CalculateSalary(); MessageManagement c_Message = new MessageManagement(); double d_GrossPay, d_TaxRate, d_Allowance, d_Deduction, d_Netpay; try { Console.Write("Enter Gross pay : $ "); d_GrossPay = Convert.ToDouble(Console.ReadLine()); Console.Write("Enter Tax rate (%) : "); d_TaxRate = Convert.ToDouble(Console.ReadLine()); Console.Write("Enter Allowance : $ "); d_Allowance = Convert.ToDouble(Console.ReadLine()); Console.Write("Enter Deduction : $ "); d_Deduction = Convert.ToDouble(Console.ReadLine()); d_Netpay = c_CalcSalary.CalculateNetPay(d_GrossPay, d_TaxRate, d_Allowance, d_Deduction); c_Message.DisplayMessage("Your Net Pay is : $ " + d_Netpay); } catch { c_Message.DisplayErrorMessage(); Console.Clear(); goto StartInput; } }
static void Main() { //SRP Test var s = new CalculateSalary() { DailyRate = 1000, Daysworked = 20 }; var salary = s.CalcaulateSalary(); var p = new PrintSalary(); p._PrintSalary(salary); Console.ReadKey(true); }
/// <summary> /// This method performs calculating salary. /// </summary> /// <param name="sender">Object.</param> /// <param name="e">DoWorkEventArgs object.</param> public void BW_DoWork(object sender, DoWorkEventArgs e) { double count = EmployeeList.Count; double result = 100 / count; int i = 1; Random r = new Random(); foreach (var employee in EmployeeList) { employee.Salary = CalculateSalary.CalculateForOne(Manager, employee, Addition); bool isDefine = employees.SetSalary(employee); if (isDefine == true) { Thread.Sleep(r.Next(250, 500)); backgroundWorker.ReportProgress(Convert.ToInt32(result * i++)); } } }
public void Setup() { calculateSalary = new CalculateSalary(); }
static void Main(string[] args) { //Your name : //Chun Fei Johnny Tiu 0777813 //1 - Which Statement is correct ? //a.Properties of anonymous types will be read - only properties so you cannot change their values. //b.A dynamic type escapes type checking at run time. //c.Struct can declare a default constructor like a class //d. Partial classes can have different class names. Console.WriteLine("1- ============================================================"); Console.WriteLine("A. Properties of anonymous types will be read - only properties so you cannot change their values."); //2- Create a class Name is as Employee(id, name, salary) //a.Use a generic collection to put 5 employees in that. (Use optional data) //b.Iterate through the collection and Write the name of the employee in the console. //c.Use delegate to find the lowest and highest salary among the employee Console.WriteLine(); Console.WriteLine("2- ============================================================"); List <Employee> lEmployees = new List <Employee>(); lEmployees.Add(new Employee(1, "John", 10000)); lEmployees.Add(new Employee(2, "Jones", 20000)); lEmployees.Add(new Employee(3, "Jim", 30000)); lEmployees.Add(new Employee(4, "Jimmy", 25000)); lEmployees.Add(new Employee(5, "Jason", 15000)); Console.WriteLine("Employee names inside lEmployees List:"); lEmployees.ForEach(emp => Console.WriteLine(emp.name)); CalculateSalary maxSalary = highestSalary; CalculateSalary minSalary = lowestSalary; Console.WriteLine($"Highest salary within lEmployees: {maxSalary(lEmployees)}"); Console.WriteLine($"Lowest salary within lEmployees: { minSalary(lEmployees)}"); //3- Use Tuple to create an object which has 3 fields (name, age, address) and print the fields in the console. //a.User Interpolation => $”” //b.Use Format ({0}) Console.WriteLine(); Console.WriteLine("3- ============================================================"); var person = Tuple.Create <string, int, string>("John", 30, "Montreal"); Console.WriteLine("name: {0}", person.Item1); Console.WriteLine($"age: {person.Item2} address:{person.Item3}"); //4- Use Dictionary to keep the values of Information of 5 employees in question 2. //a.Use employeeId as the key and the office address as the value. Console.WriteLine(); Console.WriteLine("4- ============================================================"); Dictionary <int, string> empList = new Dictionary <int, string>(); empList.Add(1, "John"); empList.Add(2, "Jones"); empList.Add(3, "Jim"); empList.Add(4, "Jimmy"); empList.Add(5, "Jason"); foreach (KeyValuePair <int, string> e in empList) { Console.WriteLine("Key: {0}, Value:{1}", e.Key, e.Value); } //5- Create a Generic Class the only accepts class reference Console.WriteLine(); Console.WriteLine("5- ============================================================"); // MyGenericClass<int> genericInt; MyGenericClass <string> genericString; Console.WriteLine("MyGenericClass cannot accept <int> as a type but accepts <string> since only <string> is a reference type."); //6- Use Extension method for integer to check if the number is dividable by 3 Console.WriteLine(); Console.WriteLine("6- ============================================================"); int i = 5; int j = 6; Console.WriteLine($"5 is dividable by 3: { i.IsDividableBy(3)}"); Console.WriteLine($"6 is dividable by 3: { j.IsDividableBy(3)}"); //7- Write a method that has one string parameter.By Using predicate check if that string has vowel sounds and print all the vowel sounds in the output. Console.WriteLine(); Console.WriteLine("7- ============================================================"); ArrayList vowels = new ArrayList() { "a", "e", "i", "o", "u" }; Predicate <string> containsVowels = (string s) => { bool result = false; foreach (string v in vowels) { if (s.Contains(v)) { Console.WriteLine($"'{v}'"); result = true; } } return(result); }; string s = "hello"; if (containsVowels(s)) { Console.WriteLine($"The string '{s}' contains vowel(s)"); } else { Console.WriteLine($"The string '{s}' contains no vowels"); } //8- (Bonus) Use Event/Func/Action/delegate with 2 classes (student, RegisterStudentOperation). If //the student graduates, notifies the RegisterStudentOperation and Prints a message in the //console. Console.WriteLine(); Console.WriteLine("8- ============================================================"); // I understand that Action is just a Delegate with a void return and Func is a Delegate with return params but I don't understand Event. }
public void TestMethod1() { CalculateSalary calculateSalary = new CalculateSalary(); Assert.IsNotNull(calculateSalary); }