Employee Management System Project Step by Step using Java and C++
In this Post we Discuss Employee Management System Project using Java and C++. An Abstract class Employee with a constructor and Two abstract Methods along with two subclasses Permanent Employee and Visiting Employee that inherit from the Employee class in java and C++
Program Source Code using Java
import java.util.*;
abstract class Employee{
protected int empId;
protected String empName;
// Constructor
public Employee(int employeeId, String employeeName) {
this.empId = employeeId;
this.empName = employeeName;
}
// Abstract Method
abstract void inputDetail();
abstract double calculateSalary();
public void displayInfo() {
System.out.println("-----------Employee Detail-------");
System.out.println("Employee ID :"+empId);
System.out.println("Employee Name :"+empName);
}
}
class parmanentEmployee extends Employee{
private double basicSalary,allowance;
//constructor
public parmanentEmployee(int empId, String empName) {
super(empId,empName);
}
@Override
public void inputDetail() {
Scanner ins = new Scanner(System.in);
System.out.print("Enter Basic Salary :$");
basicSalary = ins.nextDouble();
System.out.print("Enter Allowance :$");
allowance = ins.nextDouble();
}
@Override
public double calculateSalary() {
return basicSalary+allowance;
}
}
class VisitingEmployee extends Employee{
private int workedHour;
private double hourlyRate;
public VisitingEmployee(int empId,String empName){
super(empId,empName);
}@Override
public void inputDetail() {
Scanner ins = new Scanner(System.in);
System.out.print("Enter Hourly Rate :");
hourlyRate = ins.nextDouble();
System.out.print("Enter Hour :");
workedHour = ins.nextInt();
}
@Override
public double calculateSalary() {
return workedHour*hourlyRate;
}
}
public class EmployeeEx {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner ins = new Scanner(System.in);
Employee Pemployee = new parmanentEmployee(0,"");
Employee Vemployee = new VisitingEmployee(0,"");
char op;
do {
System.out.println("Select Employee Type");
System.out.println("1. Permanet Employee");
System.out.println("2. Visiting Employee");
System.out.print("Enter Your Choice :");
int choice =ins.nextInt();
switch(choice) {
case 1:{
System.out.print("Enter Employee Id :");
int id = ins.nextInt();
System.out.print("Enter Employee Name :");
String name = ins.next();
Pemployee.empId = id;
Pemployee.empName = name;
Pemployee.inputDetail();
double sal = Pemployee.calculateSalary();
Pemployee.displayInfo();
System.out.println("Calculated Salary :"+sal);
break;
}
case 2:{
System.out.print("Enter Employee Id :");
int id = ins.nextInt();
System.out.print("Enter Employee Name :");
String name = ins.next();
Vemployee.empId = id;
Vemployee.empName = name;
Vemployee.inputDetail();
double sal = Vemployee.calculateSalary();
Vemployee.displayInfo();
System.out.println("Calculated Salary :"+sal);
break;
}
default:
System.out.println("Invalid Number Try Again");
break;
}
System.out.print("Do You Want to Continue(y/n):");
op = ins.next().charAt(0);
}while(op=='y'||op=='Y');
}
}
Related Video:
Program Source Code using C++
Related Video
Post a Comment