-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solution.java
111 lines (108 loc) · 3.11 KB
/
Solution.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
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
// "static void main" must be defined in a public class.
import java.util.Scanner;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Employee[] rg = new Employee[4];
for(int i =0;i<4;i++){
int employeeId = sc.nextInt();
sc.nextLine();
String name = sc.nextLine();
String branch = sc.nextLine();
double rating = sc.nextDouble();
sc.nextLine();
boolean companyT= sc.nextBoolean();
sc.nextLine();
rg[i] = new Employee(employeeId, name , branch, rating, companyT);
}
String input=sc.nextLine();
int y =findCountOfEmployeesUsingCompT(rg,input);
if(y==0){
System.out.println("no such employee");
}
else{
System.out.println(y);
}
Employee[] t = findEmployeeWithSecondHighestR(rg);
if(t==null){
System.out.println("All Employee using company transport");
}
else{
System.out.println(t[1].getemployeeId());
System.out.println(t[1].getname());
}
}
public static int findCountOfEmployeesUsingCompT(Employee[] rg, String input){
int count=0;
for(int i =0;i<4;i++){
if(rg[i].getbranch().equalsIgnoreCase(input)){
count++;
}
}
return count;
}
public static Employee[] findEmployeeWithSecondHighestR(Employee [] rg){
Employee [] help = new Employee[4];
int j=0;
for(int i =0;i<4;i++){
if(rg[i].getcompanyT()==false){
help[j]=rg[i];
j++;
}
}
for(int i =0;i<j;i++){
for(int k=i+1;k<j;k++){
if(help[i].getrating()<help[k].getrating()){
Employee temp = help[k];
help[k]=help[i];
help[i]=temp;
}
}
}
return help;
}
}
class Employee{
private int employeeId;
private String name,branch;
private double rating;
private boolean companyT;
public int getemployeeId(){
return employeeId;
}
public String getname(){
return name;
}
public String getbranch(){
return branch;
}
public double getrating(){
return rating;
}
public boolean getcompanyT(){
return companyT;
}
public void setemployeeId(int employeeId){
this.employeeId=employeeId;
}
public void setname(String name){
this.name = name;
}
public void setbranch(String branch){
this.branch = branch;
}
public void setrating(double rating){
this.rating= rating;
}
public void setcompanyT(boolean companyT){
this.companyT=companyT;
}
public Employee(int employeeId, String name, String branch,double rating, boolean companyT){
this.employeeId= employeeId;
this.name= name;
this.branch=branch;
this.rating= rating;
this.companyT=companyT;
}
}