JAVA-Employee class-Use java.util.GregorianCalendar or java.util.Date-& a method called calcSalary() to calculate current monthly salary

Q. Create a class called Employee that includes the following:
a. Four instance variables – emp_id (integer), name (String), salary (double) and hiredate [Use the class java.util.GregorianCalendar or java.util.Date to implement hiredate]
b. A constructor that initializes all instance variables except emp_id 
c. A method called setId() to increment emp_id by 1 for each new Employee (use one extra static instance variable)
d. A get method for each of the instance variables
e. A method called calcSalary() to calculate the current monthly salary of an Employee depending upon hiredate on the scale 5000-200-10000 and 30% DA and 15% HRA
f. A method called display() to print Employee details as below:
EMPID NAME HIREDATE SALARY
===== ==== ======== =======
1 Paul Deitel 19/06/2004 8990.00
Write a JAVA program that will test Employee’s capabilities.


import java.util.Date;
class employee
{
static int c=0;
private int emp_id;
private String name;
private double salary;
private Date hiredate;
employee(String n,double s,Date h)
{
name=n;
salary=s;
hiredate=h;
}
void setemp_id()
{
c++;
emp_id=c;
}
int getemp_id()
{
return emp_id;
}
String  getname()
{
return name;
}
double getsalary()
{
return salary;
}
Date  gethiredate()
{
return hiredate;
}
double calcsalary()
{
return ((0.15*getsalary())+(0.3*getsalary())+getsalary());
}
void disp()
{
System.out.println(getemp_id()+"\t"+getname()+"\t"+gethiredate()+"\t"+calcsalary());
}
}
class prog5
{
public static void main(String args[])
{
Date d=new Date();
employee e1=new employee("Sukhendu",5000,d);
employee e2=new employee("Mou",6000,d);
employee e3=new employee("Suvajit",4000,d);
System.out.println("EMPID NAME      HIREDATE      SALARY");
e1.setemp_id();
e1.disp();
e2.setemp_id();
e2.disp();
e3.setemp_id();
e3.disp();
}

}
Output:
EMPID   NAME   HIREDATE   SALARY
1   Sukhendu   wed Feb 28 00:24:01 IST 2018   5000
2   Mou            wed Feb 28 00:24:01 IST 2018   6000
3   Suvajit        wed Feb 28 00:24:01 IST 2018   4000

//if you have any problem, comment below

Comments