-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemployee.java
46 lines (46 loc) · 1.56 KB
/
employee.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.Scanner;
abstract class employee {
Scanner sc = new Scanner(System.in);
String name;
int empno;
int experience;
int salary=0;
void input() {
System.out.println("Enter employee Name, number and experience in order");
name = sc.nextLine();
empno = Integer.parseInt(sc.nextLine());
experience = Integer.parseInt(sc.nextLine());
}
void display(){
System.out.println("-----------------PAYSLIP------------------");
System.out.println("Name: "+name+"\nNumber: "+empno+"\nExperience: "+experience+"\nSalary: "+salary);
System.out.println("------------------------------------------");
}
abstract void calculateSalary();
}
class PermanentEmployee extends employee {
void calculateSalary() {
System.out.println("Enter Basic, Dearness Allowance and House Rent Allowance in order");
for (int i = 0; i < 3; i++)
salary = salary + Integer.parseInt(sc.nextLine());
}
}
class ContractEmployee extends employee {
void calculateSalary() {
System.out.println("Enter Fixed pay amount and variable pay amount in order");
for (int i = 0; i < 2; i++)
salary = salary + Integer.parseInt(sc.nextLine());
}
}
class Main {
public static void main(String[] args) {
PermanentEmployee ob1 = new PermanentEmployee();
ob1.input();
ob1.calculateSalary();
ob1.display();
ContractEmployee ob2 = new ContractEmployee();
ob2.input();
ob2.calculateSalary();
ob2.display();
}
}