answere tala cha but couldnot do it correctly mistake haru bho pls help, question: Create an Employee class with two fields: IDNum and hourlyWage. The constructor for Employee will accept two arguments for these two fields. When the Employee class is instantiated you will throw an ArgumentException if the hourlyWage is less than 6.00 or more than 50.00. Handle any thrown Exceptions in the Employee class by displaying an error message. In Main instantiate an array of five (5) Employee objects. Prompt the user for the values of the two fields in each Employee object. Handle any exceptions (try-catch block) that are thrown by setting the Employee's ID number to 999 and the Employee's pay rate to the $6.00 minimum using the Employee constructor in the catch so that the message can be displayed from the class object by way of the ArgumentException. At the end of input display all the entered and possibly corrected records. class Employee { public int idNum; public double rate; public Employee(int idNumber, double emprate) { int idNum = idNumber; double rate = emprate; if (rate < 6 && rate > 50) { throw new ArgumentException("Value does not fall within the expected range."); //Console.WriteLine("Value does not fall within the expected range."); } } } public class assignment7 { public static void Main() { Employee[] emparray = new Employee[5]; int ID; Double Salary; for (int x = 0; x <= 4; x++) { Console.Write("Enter ID {0}: ", x + 1); ID = Convert.ToInt32(Console.Read()); Console.ReadLine(); Console.WriteLine("Enter salary {0}: ", x + 1); Salary = Convert.ToDouble(Console.Read()); // Salary = Convert.ToDouble(Salary); emparray[x] = new Employee(ID, Salary); try { int idNum = 999; } catch (Exception e) Console.WriteLine( e.ToString() ); { } } }
redlotus · Apr 25, 2009 10:48 PM · 20,462 views
The if clause should have OR instead of AND otherwise the condition will never be met. A number can't be less than 6 and greater than 50 simultaneously.
cowboy · Apr 25, 2009 11:12 PM
change the follwoing public Employee(int idNumber, double emprate) { idNum = idNumber; rate = emprate; }
evilinside · Apr 25, 2009 11:34 PM
using System; using System.Collections.Generic; using System.Text; namespace SajhaUser { class Program { static void Main(string[] args) { try { Employee emp = new Employee(1, 56); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } } } } using System; using System.Collections.Generic; using System.Text; namespace SajhaUser { public class Employee { private int idNumber = 0; private double wages = 0.00; public Employee(int id, double salary) { if (salary < 6 || salary > 50) throw new ArgumentException("Not valid number"); else this.wages = salary; this.idNumber = id; } } }
shresthasubash · Apr 26, 2009 10:42 AM
This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.
Start a New Discussion