Create an Employee class with two fields:IDNum and hourlyWage. The Employee cons
ID: 3622707 • Letter: C
Question
Create an Employee class with two fields:IDNum and hourlyWage. The Employee constructor requires values for both fields. Upon construction, throw an ArgumentException is the hourlyWage is lees than 6.00 or more than 50.00. Write a program that establishes, one at a time, at least three Employees with hourlyWages that are above, below, and within the allowed range. Immediately after each instantiation attempt, handle any thrown Exceptions by displaying an error message. Save the file as EmployeeExceptionDemo.csExplanation / Answer
Dear, Here is the code using System; namespace ConsoleApplication4 { class EmployeeExceptionDemo { // The main entry point for the application. static void Main(string[] args) { try { Console.WriteLine("Employee 1:"); Employee emp1=new Employee(1432,5.5); Console.WriteLine("Employee 2:"); Employee emp2=new Employee(1432,50.5); Console.WriteLine("Employee 3:"); Employee emp3=new Employee(1832,5.5); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } class Employee { public int idNum; public double hourlyrate; public Employee(int idNumber, double emprate) { idNum = idNumber; if (emprate < 6 || emprate > 50) { throw new ArgumentException("Value does not fall within the expected range."); } else hourlyrate = emprate; } } } Hope this will help youRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.