forked from Shreerang4/learning-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTester.java
More file actions
146 lines (122 loc) · 4.04 KB
/
Tester.java
File metadata and controls
146 lines (122 loc) · 4.04 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import java.util.Scanner;
// Inputs Details of 5 Employees and prints details of Emp with Max Salary
public class Tester{
public static void main(String[] args){
String name, id;
int age;
double salary;
char yn;
boolean status;
Scanner sc = new Scanner(System.in);
SalariedEmployee[] emps = new SalariedEmployee[5];
for(int i = 0; i<5; i++){
System.out.print("Enter Name of Employee " + (i+1) + ": ");
name = sc.nextLine();
System.out.print("Enter Id of Employee " + (i+1) + ": ");
id = sc.nextLine();
System.out.print("Enter Age of Employee " + (i+1) + ": ");
age = sc.nextInt();
System.out.print("Enter Salary of Employee " + (i+1) + ": ");
salary = sc.nextDouble();
emps[i] = new SalariedEmployee(name, id, age, salary);
System.out.print("Is the Employee Permanent? (Y/N): ");
yn = sc.next().charAt(0);
if(Character.toLowerCase(yn) == 'y'){
emps[i].setstatus(true);
emps[i].empAllowance();
}else{
emps[i].setstatus(false);
emps[i].empAllowance();
}
sc.nextLine(); // Buffer Clear
System.out.print("\n");
}
int maxint = 0;
int currentindex = 0;
double maxsalary = 0;
for(SalariedEmployee s: emps){
if(s.getempSalary() > maxsalary){
maxint = currentindex;
maxsalary = s.getempSalary();
}
currentindex++;
}
int i = 1;
System.out.println("---------- Details of All Employees ------------");
System.out.printf("|%-4s|%-10s|%-5s|%-4s|%-10s|%-8s|\n", "Sr", "Name", "ID", "Age", "Salary", "Status");
System.out.println("+----------------------------------------------+");
for(SalariedEmployee s: emps){
System.out.printf("|%-4d|%-10s|%-5s|%-4d|%-10.2f|%-8b|\n", i, s.getName(), s.getId(), s.getAge(), s.getempSalary(), s.getempStatus());
i++;
}
System.out.println("+----------------------------------------------+");
SalariedEmployee s = emps[maxint]; // s has Max Salary
System.out.println("\nDetails for Employee with Maximum Salary");
System.out.println("Name: "+ s.getName());
System.out.println("Id: "+ s.getId());
System.out.println("Age: "+ s.getAge());
System.out.println("Salary: "+ s.getempSalary());
if(s.getempStatus()){
System.out.println("Status: Permanent\n");
}else{
System.out.println("Status: Temporary\n");
}
}
}
class Employee{
private String Name;
private String Id;
private int Age;
Employee(String n, String id, int a){
setName(n);
setId(id);
setAge(a);
}
// Setters
void setName(String newname){
this.Name = newname;
}
void setId(String newid){
this.Id = newid;
}
void setAge(int newage){
this.Age = newage;
}
// Getters
String getName(){
return this.Name;
}
String getId(){
return this.Id;
}
int getAge(){
return this.Age;
}
}
class SalariedEmployee extends Employee{
private double empSalary;
private boolean permanentStatus;
SalariedEmployee(String name, String id, int age, double empSalary){
super(name, id, age);
setempSalary(empSalary);
}
// Setters
void setempSalary(double salary){
this.empSalary = salary;
}
void setstatus(boolean status){
this.permanentStatus = status;
}
// Getters
double getempSalary(){
return this.empSalary;
}
boolean getempStatus(){
return this.permanentStatus;
}
void empAllowance(){
if(permanentStatus){
this.empSalary+=2000;
}
}
}