In: Computer Science
A java program with classes and methods to manage employment. Program should be able to store/add employees, calculate payroll, display or schedule shifts.
All classes should have at least a null constructor and copy constructor. Other constructors are up to your discretion. Include all necessary accessors and modifiers.
To test the classes, create a container class with simply a main() method. The container class will have attributes that are class objects of each of the classes you create. The main() method will create the class objects, perform duties and produce appropriate output.
import java.util.Scanner;
class Employee
{
int age;
String name, address, gender;
Scanner get = new Scanner(System.in);
Employee()
{
System.out.println("Enter Name of the Employee:");
name = get.nextLine();
System.out.println("Enter Gender of the Employee:");
gender = get.nextLine();
System.out.println("Enter Address of the Employee:");
address = get.nextLine();
System.out.println("Enter Age:");
age = get.nextInt();
}
void display()
{
System.out.println("Employee Name: "+name);
System.out.println("Age: "+age);
System.out.println("Gender: "+gender);
System.out.println("Address: "+address);
}
}
class fullTimeEmployees extends Employee
{
float salary;
int des;
fullTimeEmployee()
{
System.out.println("Enter Designation:");
des = get.nextInt();
System.out.println("Enter Salary:");
salary = get.nextFloat();
}
void display()
{
System.out.println("Full Time Employee Details"+"\n");
super.display();
System.out.println("Salary: "+salary);
System.out.println("Designation: "+des);
}
}
class partTimeEmployees extends Employee
{
int workinghrs, rate;
partTimeEmployees()
{
System.out.println("Enter Number of Working Hours:");
workinghrs = get.nextInt();
}
void calculatepay()
{
rate = 8 * workinghrs;
}
void display()
{
System.out.println("Part Time Employee Details"+"\n");
super.display();
System.out.println("Number of Working Hours: "+workinghrs);
System.out.println("Salary for "+workinghrs+" working hours is: $"+rate);
}
}
class Employees
{
public static void main(String args[])
{
System.out.println("Enter Full Time Employee Details"+"\n");
fullTimeEmployees ob1 = new fullTimeEmployees();
partTimeEmployees ob = new partTimeEmployees();
System.out.println(Enter Part Time Employee Details"+"\n");
ob1.display();
ob.calculatepay();
ob.display();
}
}