[Show all top banners]

redlotus
Replies to this thread:

More by redlotus
What people are reading
Subscribers
Subscribers
[Total Subscribers 1]

Rolemodel
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 c# help
[VIEWED 12893 TIMES]
SAVE! for ease of future access.
Posted on 04-25-09 10:48 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 


answere tala cha but couldnot do it correctly mistake haru bho pls help,


question:




  1. Create an Employee class with two fields:  IDNum and hourlyWage.



  2. The constructor for Employee will accept two arguments for these two fields.



  3. When the Employee class is instantiated you will throw an ArgumentException if the hourlyWage is less than 6.00 or more than 50.00.



  4. Handle any thrown Exceptions in the Employee class by displaying an error message.



  5. In Main instantiate an array of five (5) Employee objects.



  6. Prompt the user for the values of the two fields in each Employee object.



  7. 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.



  8. At the end of input display all the entered and possibly corrected records.



  9.  



  10. class Employee



  11. {


    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() );


    {


     


     


     


    }


    }


    }


 
Posted on 04-25-09 11:12 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

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.

 
Posted on 04-25-09 11:34 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

change the follwoing

public Employee(int idNumber, double emprate)


{


idNum = idNumber;


rate = emprate;

}




 
Posted on 04-26-09 10:42 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

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;
        }
       
    }
}


 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 90 days
Recommended Popular Threads Controvertial Threads
Conservative discussions
TPS to F1 Status.
TPS To F-1 COS
TPS Sakiyo Tara Case is in Court.
Got my F1 reinstatement approved within 3 months(was out of F1 for almost 2 years)
Homeland Security revokes temporary status for 532,000 Cubans, Haitians, Nicaraguans and Venezuelans
Has anyone here successfully reinstated to F-1 status after a year-long gap following a drop from F-1?
Need Help of IT consultancies
Nepal TPS decision
Any input on remote jobs(IT related or Sales or Marketing)?
Supreme Court allows Trump to end TPS for Venezuelans
Nepal Likely to Get 60-Day TPS Notice
Nepal TPS has been Extended !!!
नेपाल मा B. sc गरियो यहाँ फेरी ७० -८० क्रेडिट पढ्नु पर्ने भो
Genuine Question.... Why so many folks still in TPS after 10 years. Is the statistics wrong?
NEPAL TPS IS GONE
महँगो अण्डाको पिकल्प : कुखुरा र खोर भाडामा लिने
#MAGA#FAFO is delicious
What is the purpose of an F1 student visa in the U.S.?
Homeowner Charged renting to illegal migrants
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters