Employee Model Class
This commit is contained in:
102
IndustrialTrainingProjects/EmployeeModelClass.java
Normal file
102
IndustrialTrainingProjects/EmployeeModelClass.java
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
// Program to create Model Class, getter, setters and display the data.
|
||||||
|
|
||||||
|
package IndustrialTrainingProjects;
|
||||||
|
|
||||||
|
//Creating Employee class
|
||||||
|
class EmployeeDetails {
|
||||||
|
//Creating properties of Employee class
|
||||||
|
int emp_id, salary;
|
||||||
|
String name, address, department, email;
|
||||||
|
|
||||||
|
//Getter and setters for getting and setting properties
|
||||||
|
public int getEmp_id() {
|
||||||
|
return emp_id;
|
||||||
|
}
|
||||||
|
public void setEmp_id(int emp_id) {
|
||||||
|
this.emp_id = emp_id;
|
||||||
|
}
|
||||||
|
public int getSalary() {
|
||||||
|
return salary;
|
||||||
|
}
|
||||||
|
public void setSalary(int salary) {
|
||||||
|
this.salary = salary;
|
||||||
|
}
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
public String getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
public void setAddress(String address) {
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
|
public String getDepartment() {
|
||||||
|
return department;
|
||||||
|
}
|
||||||
|
public void setDepartment(String department) {
|
||||||
|
this.department = department;
|
||||||
|
}
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Overriding toString() method
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Employee [emp_id = " + emp_id + ", salary = " + salary + ", name = " + name + ", address = " + address
|
||||||
|
+ ", department = " + department + ", email = " + email + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
//Creating main class
|
||||||
|
public class EmployeeModelClass{
|
||||||
|
//main() method start
|
||||||
|
public static void main(String args[]) {
|
||||||
|
|
||||||
|
//Creating object of EmployeeDetails class
|
||||||
|
EmployeeDetails emp = new EmployeeDetails();
|
||||||
|
//Setting values to the properties
|
||||||
|
emp.setEmp_id(101);
|
||||||
|
emp.setName("XYZ");
|
||||||
|
emp.setDepartment("IT");
|
||||||
|
emp.setSalary(100000);
|
||||||
|
emp.setAddress("New Delhi");
|
||||||
|
emp.setEmail("xyz123@gmail.com");
|
||||||
|
|
||||||
|
//Showing Employee details
|
||||||
|
System.out.println(emp);
|
||||||
|
|
||||||
|
//Getting salary using getter
|
||||||
|
int sal = emp.getSalary();
|
||||||
|
int increment = 0;
|
||||||
|
//Incrementing salary based on condition
|
||||||
|
if ((sal >=100000) && (sal <=150000))
|
||||||
|
{
|
||||||
|
//incrementing salary 2%
|
||||||
|
increment += (sal * 2)/100;
|
||||||
|
sal = sal+increment;
|
||||||
|
|
||||||
|
emp.setSalary(sal);
|
||||||
|
System.out.println("\n Salary is incremented \n");
|
||||||
|
System.out.println(emp);
|
||||||
|
|
||||||
|
}else if ((sal >=1500) && (sal <=20000)){
|
||||||
|
//incrementing salary 5%
|
||||||
|
increment += (sal * 5)/100;
|
||||||
|
sal = sal+increment;
|
||||||
|
|
||||||
|
emp.setSalary(sal);
|
||||||
|
System.out.println("\n Salary is incremented \n");
|
||||||
|
System.out.println(emp);
|
||||||
|
}else {
|
||||||
|
System.out.println("\n Salary is not incremented \n");
|
||||||
|
System.out.println(emp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,3 +23,4 @@ if the problem still persist then create a issue or use Google/Stack Overlflow f
|
|||||||
|----------|------------|--------------------------|
|
|----------|------------|--------------------------|
|
||||||
|1 | [PrivateConBasic.java](https://github.com/psavarmattas/Java-Projects/blob/master/IndustrialTrainingProjects/PrivateConBasic.java) | Program to implement private constructor using the basic method. |
|
|1 | [PrivateConBasic.java](https://github.com/psavarmattas/Java-Projects/blob/master/IndustrialTrainingProjects/PrivateConBasic.java) | Program to implement private constructor using the basic method. |
|
||||||
|2 | [PrivateConSingleton.java](https://github.com/psavarmattas/Java-Projects/blob/master/IndustrialTrainingProjects/PrivateConSingleton.java) | Program to implement private constructor using the Singleton method. |
|
|2 | [PrivateConSingleton.java](https://github.com/psavarmattas/Java-Projects/blob/master/IndustrialTrainingProjects/PrivateConSingleton.java) | Program to implement private constructor using the Singleton method. |
|
||||||
|
|3 | [EmployeeModelClass.java](https://github.com/psavarmattas/Java-Projects/blob/master/IndustrialTrainingProjects/EmployeeModelClass.java) | // Program to create Model Class, getter, setters and display the data. |
|
||||||
Reference in New Issue
Block a user