Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Write a program using a class that get information about employee rollno, name, address, pin code, phone number, gross salary and pf. Display the net salary (ie gross less pf) and calculate grade base on net salary. The grades are
Grade-‘A’ sal>10000
Grade-‘B’ sal>5000
Grade-‘C’ sal<5000
My code:
CSS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EmployeeClass
{
    class EmployeeClass
    {
        private int _EmployeeID;
        private double _GrossPay;
        private double _PF;
        private int _Pincode;
        private double _PhoneNumber;
        private string _EmployeeName;
        private double _EmployeeAdress;


        public int employeeId
        {
            get
            {
                return _EmployeeID;
            }
            set
            {
                _EmployeeID = value;
            }

        }


        public double grosspay
        {
            get
            {
                return _GrossPay;
            }
            set
            {
                _GrossPay = value;
            }

        }

        public double pf
        {
            get
            {
                return _PF;
            }
            set
            {
                _PF = value;
            }

        }

        public int pincode
        {
            get
            {
                return _Pincode;
            }
            set
            {
                _Pincode = value;
            }

        }
        public double phonenumber
        {
            get
            {
                return _PhoneNumber;
            }
            set
            {
                _PhoneNumber = value;
            }

        }

        public string employeename
        {
            get
            {
                return _EmployeeName;
            }
            set
            {
                _EmployeeName = value;
            }

        }

        public double employeeaddress
        {
            get
            {
                return _EmployeeAdress;
            }
            set
            {
                _EmployeeAdress = value;
            }

        }
        public EmployeeClass(string EName, int EId, int Pincode, int phoneN,double Address, double pf, double grosspay)
        {
            this._EmployeeName = EName;
            this._EmployeeID = EId;
            this._Pincode = Pincode;
            this._PhoneNumber = phoneN;
            this._EmployeeAdress = Address;
            this._PF = pf;
            this._GrossPay = grosspay;
        }

        public double CalculateSalary()
        {
            double netsalary = (this._GrossPay - this._PF);
            return netsalary;
        }
        public void CalculateGrade(string grade, double netsalary)
        {


            if (netsalary > 1000)
            {
                grade = "A";
            }
            else if (netsalary > 5000)
            {
                grade = "B";
            }
            else if (netsalary < 5000)
            {
                grade = "C";
            }

        }








   static void Main(string[] args)
        {
            EmployeeClass em = new EmployeeClass("Pavan", 123, 48858, 81516615, 303, 1000, 20000);
            em.CalculateSalary();
       Console.WriteLine("The Net Salary of an Employee is {0}",em.CalculateSalary());
          Console.WriteLine("The grade of an Employee is {0}",em.CalculateGrade("A",em.CalculateSalary());

        }
    }
}
Posted

You are missing a 0.
C#
if (netsalary > 10000)
          {
              grade = "A";
          }
          else if (netsalary >= 5000)
          {
              grade = "B";
          }
          else if (netsalary < 5000)
          {
              grade = "C";
          }
 
Share this answer
 
v3
Comments
Ron Beyer 26-Jan-14 12:31pm    
One of those 5000's should have a >= by it, otherwise a salary of exactly 5000 will fall through the if's.
Abhinav S 26-Jan-14 12:35pm    
That is correct. Fixed.
There are some problems with your method CalculateGrade():

  • The first condition (the check for grade "A") should use 10000, not 1000.
  • The method should return the computed grade - i.e. make the return type string, not void and don't require a grade argument.
  • The method actually doesn't require any arguments, since the net salary can be computed using your class' existing method.
  • Make sure your method returns a value if the grade A and grade B conditions don't match.

/ravi
 
Share this answer
 
Comments
Abhinav S 26-Jan-14 12:29pm    
5.
Beginner147 26-Jan-14 20:44pm    
Hello ,
Thank you so much for your reply. I have made some changes as you said but still i am getting some erros. Actually I am very new to this programming concept so I didnt know some rules of how can we access the return value of one method into another method and how can a method return a value if the grade A and grade B condition doesnt match. Could you please explain me?

Regards,
Rekha


Ravi Bhavnani 26-Jan-14 20:54pm    
You need to take a step back and review the basics of programming. These concepts aren't easily explained in an answer to a forum post.

/ravi
Beginner147 26-Jan-14 23:19pm    
Can you please correct this program?
Beginner147 26-Jan-14 20:44pm    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EmployeeClass
{
class EmployeeClass
{
private int _EmployeeID;
private double _GrossPay;
private double _PF;
private int _Pincode;
private double _PhoneNumber;
private string _EmployeeName;
private double _EmployeeAdress;
public string Grade;


public int employeeId
{
get
{
return _EmployeeID;
}
set
{
_EmployeeID = value;
}

}


public double grosspay
{
get
{
return _GrossPay;
}
set
{
_GrossPay = value;
}

}

public double pf
{
get
{
return _PF;
}
set
{
_PF = value;
}

}

public int pincode
{
get
{
return _Pincode;
}
set
{
_Pincode = value;
}

}
public double phonenumber
{
get
{
return _PhoneNumber;
}
set
{
_PhoneNumber = value;
}

}

public string employeename
{
get
{
return _EmployeeName;
}
set
{
_EmployeeName = value;
}

}

public double employeeaddress
{
get
{
return _EmployeeAdress;
}
set
{
_EmployeeAdress = value;
}

}
public EmployeeClass(string EName, int EId, int Pincode, int phoneN,double Address, double pf, double grosspay)
{
this._EmployeeName = EName;
this._EmployeeID = EId;
this._Pincode = Pincode;
this._PhoneNumber = phoneN;
this._EmployeeAdress = Address;
this._PF = pf;
this._GrossPay = grosspay;
}

public double CalculateSalary()
{
double netsalary = (this._GrossPay - this._PF);
return netsalary;
}
public string CalculateGrade( double netsalary)
{


if (netsalary > 10000)
{
Grade = "A";
}
else if (netsalary > 5000)
{
Grade= "B";
}
else if (netsalary < 5000)
{
Grade= "C";
}
}

return Grade;






static void Main(string[] args)
{
EmployeeClass em = new EmployeeClass("Pavan", 123, 48858, 81516615, 303, 1000, 20000);
em.CalculateSalary();
Console.WriteLine("The Net Salary of an Employee is {0}",em.CalculateSalary());
Console.WriteLine("The grade of an Employee is {0}",em.CalculateGrade("A",em.CalculateSalary());
}

}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900