Following program will help in managing employee's in an organization it ask details for each new employee and have functions for printing details of any employee and increment their salary by 5%.
Code::
import java.util.*;
class employee
{ Scanner in=new Scanner(System.in);
private String name;
private double salary;
private int year,month,day;
employee()
{
System.out.print("Enter Name of Employee: ");
name=in.nextLine();
System.out.print("Enter Salary of Employee: ");
salary=in.nextDouble();
System.out.println("Enter Date of Joining(in DD/MM/YYYY format): ");
System.out.print("Date:");
day=in.nextInt();
System.out.print("Month:");
month=in.nextInt();
System.out.print("Year: ");
year=in.nextInt();
}
public void increment()
{
salary=salary+salary*0.05;
}
public void show()
{
System.out.println("Details of Employee: ");
System.out.println("Name: "+name);
System.out.println("Salary: "+salary);
System.out.printf("Date of Joining: %d/%d/%d\n",day,month,year);
}
}
public class Organization
{
public static void main(String[] nt)
{
employee[] staff=new employee[2];
staff[0]=new employee();
staff[0].increment();
staff[0].show();
}
}
Output::
here you can declare any number of employees,i have declared only one and increment and show the details of that particular employee....
Code::
import java.util.*;
class employee
{ Scanner in=new Scanner(System.in);
private String name;
private double salary;
private int year,month,day;
employee()
{
System.out.print("Enter Name of Employee: ");
name=in.nextLine();
System.out.print("Enter Salary of Employee: ");
salary=in.nextDouble();
System.out.println("Enter Date of Joining(in DD/MM/YYYY format): ");
System.out.print("Date:");
day=in.nextInt();
System.out.print("Month:");
month=in.nextInt();
System.out.print("Year: ");
year=in.nextInt();
}
public void increment()
{
salary=salary+salary*0.05;
}
public void show()
{
System.out.println("Details of Employee: ");
System.out.println("Name: "+name);
System.out.println("Salary: "+salary);
System.out.printf("Date of Joining: %d/%d/%d\n",day,month,year);
}
}
public class Organization
{
public static void main(String[] nt)
{
employee[] staff=new employee[2];
staff[0]=new employee();
staff[0].increment();
staff[0].show();
}
}
Output::
here you can declare any number of employees,i have declared only one and increment and show the details of that particular employee....