-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ5.java
More file actions
54 lines (43 loc) · 1.1 KB
/
Copy pathQ5.java
File metadata and controls
54 lines (43 loc) · 1.1 KB
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
47
48
49
50
51
52
53
54
package Assignment_01;
import java.util.Scanner;
public class Q5 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Employee obj[] = new Employee[8];
System.out.println("Enter details of employees:");
for (int i = 0; i < 8; i++) {
System.out.println("Enter details of employee " + (i + 1) + ":");
obj[i] = new Employee(sc.next(), sc.nextInt(), sc.next().charAt(0), sc.nextLong());
}
sc.close();
for (int i = 0; i < 7; i++) {
for (int j = i + 1; j < 8; j++) {
if (obj[i].department == obj[j].department) {
obj[i].calculate(obj[j]);
}
}
obj[i].display();
}
}
}
class Employee {
String name;
int age;
char department;
long salary = 0;
Employee(String a, int b, char c, long d) {
name = a;
age = b;
department = c;
salary = d;
}
void calculate(Employee obj) {
if (salary + obj.salary > 30000) {
salary += 25000;
} else
salary += obj.salary;
}
void display() {
System.out.println("Total salary for to be paid to department " + department + "is " + salary);
}
}