Skip to content

Commit de2d629

Browse files
committed
Employee (IPA-35)
1 parent 29ed473 commit de2d629

File tree

2 files changed

+221
-220
lines changed

2 files changed

+221
-220
lines changed
Lines changed: 148 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,149 @@
1-
import java.util.*;
2-
3-
public class IPA10 {
4-
public static void main(String[] args) {
5-
Scanner sc = new Scanner(System.in);
6-
Employee[] emp = new Employee[4];
7-
for (int i = 0; i < emp.length; i++)
8-
{
9-
int a = sc.nextInt();sc.nextLine();
10-
String b = sc.nextLine();
11-
String c = sc.nextLine();
12-
double d = sc.nextDouble();sc.nextLine();
13-
boolean e = sc.nextBoolean();sc.nextLine();
14-
15-
emp[i] = new Employee(a,b,c,d,e);
16-
}
17-
String br = sc.nextLine();
18-
int ans1 = CountOfEmployee(emp,br);
19-
if(ans1!=0)
20-
{
21-
System.out.println(ans1);
22-
}
23-
else{
24-
System.out.println("No such Employees");
25-
}
26-
Employee[] ans2 = EmployeeWithSecondHighestRating(emp);
27-
if(ans2!=null)
28-
{
29-
for (int i = 0; i < ans2.length; i++) {
30-
if(ans2[i].getRating()>ans2[i+1].getRating())
31-
{
32-
System.out.println(ans2[i+1].getId());
33-
System.out.println(ans2[i+1].getName());
34-
break;
35-
}
36-
}
37-
}
38-
else
39-
{
40-
System.out.println("All Employees using company transport");
41-
}
42-
}
43-
public static int CountOfEmployee(Employee[]e, String b)
44-
{
45-
int count = 0;
46-
for (int i = 0; i < e.length; i++) {
47-
if(e[i].getBranch().equalsIgnoreCase(b) && e[i].getTransport()==true)
48-
{
49-
count++;
50-
}
51-
}
52-
if(count>0)
53-
{
54-
return count;
55-
}
56-
else{
57-
return 0;
58-
}
59-
}
60-
public static Employee[] EmployeeWithSecondHighestRating(Employee[] e)
61-
{
62-
Employee[] sec = new Employee[0];
63-
Employee del;
64-
for (int i = 0; i < e.length; i++) {
65-
if(e[i].getTransport()==false)
66-
{
67-
sec = Arrays.copyOf(sec, sec.length+1);
68-
sec[sec.length-1] = e[i];
69-
}
70-
}
71-
for (int i = 0; i < sec.length; i++) {
72-
for (int j = i; j < sec.length; j++) {
73-
if(sec[i].getRating()<sec[j].getRating())
74-
{
75-
del = sec[i];
76-
sec[i]=sec[j];
77-
sec[j]=del;
78-
}
79-
}
80-
}
81-
if(sec.length>0)
82-
{
83-
return sec;
84-
}
85-
else
86-
{
87-
return null;
88-
}
89-
}
90-
}
91-
class Employee
92-
{
93-
private int Id;
94-
private String name;
95-
private String branch;
96-
private double rating;
97-
private boolean transport;
98-
99-
public Employee(int Id, String name, String branch, double rating, boolean transport)
100-
{
101-
this.Id = Id;
102-
this.name = name;
103-
this.branch = branch;
104-
this.rating = rating;
105-
this.transport = transport;
106-
}
107-
108-
public int getId()
109-
{
110-
return Id;
111-
}
112-
public void setId(int Id)
113-
{
114-
this.Id = Id;
115-
}
116-
public String getName()
117-
{
118-
return name;
119-
}
120-
public void setName(String name)
121-
{
122-
this.name = name;
123-
}
124-
public String getBranch()
125-
{
126-
return branch;
127-
}
128-
public void setBranch(String branch)
129-
{
130-
this.branch = branch;
131-
}
132-
public double getRating()
133-
{
134-
return rating;
135-
}
136-
public void setRating(double rating)
137-
{
138-
this.rating = rating;
139-
}
140-
public boolean getTransport()
141-
{
142-
return transport;
143-
}
144-
public void setTransport(boolean transport)
145-
{
146-
this.transport= transport;
147-
}
1+
package IPA10;
2+
import java.util.*;
3+
4+
public class IPA10 {
5+
public static void main(String[] args) {
6+
Scanner sc = new Scanner(System.in);
7+
Employee[] emp = new Employee[4];
8+
for (int i = 0; i < emp.length; i++)
9+
{
10+
int a = sc.nextInt();sc.nextLine();
11+
String b = sc.nextLine();
12+
String c = sc.nextLine();
13+
double d = sc.nextDouble();sc.nextLine();
14+
boolean e = sc.nextBoolean();sc.nextLine();
15+
16+
emp[i] = new Employee(a,b,c,d,e);
17+
}
18+
String br = sc.nextLine();
19+
int ans1 = CountOfEmployee(emp,br);
20+
if(ans1!=0)
21+
{
22+
System.out.println(ans1);
23+
}
24+
else{
25+
System.out.println("No such Employees");
26+
}
27+
Employee[] ans2 = EmployeeWithSecondHighestRating(emp);
28+
if(ans2!=null)
29+
{
30+
for (int i = 0; i < ans2.length; i++) {
31+
if(ans2[i].getRating()>ans2[i+1].getRating())
32+
{
33+
System.out.println(ans2[i+1].getId());
34+
System.out.println(ans2[i+1].getName());
35+
break;
36+
}
37+
}
38+
}
39+
else
40+
{
41+
System.out.println("All Employees using company transport");
42+
}
43+
}
44+
public static int CountOfEmployee(Employee[]e, String b)
45+
{
46+
int count = 0;
47+
for (int i = 0; i < e.length; i++) {
48+
if(e[i].getBranch().equalsIgnoreCase(b) && e[i].getTransport()==true)
49+
{
50+
count++;
51+
}
52+
}
53+
if(count>0)
54+
{
55+
return count;
56+
}
57+
else{
58+
return 0;
59+
}
60+
}
61+
public static Employee[] EmployeeWithSecondHighestRating(Employee[] e)
62+
{
63+
Employee[] sec = new Employee[0];
64+
Employee del;
65+
for (int i = 0; i < e.length; i++) {
66+
if(e[i].getTransport()==false)
67+
{
68+
sec = Arrays.copyOf(sec, sec.length+1);
69+
sec[sec.length-1] = e[i];
70+
}
71+
}
72+
for (int i = 0; i < sec.length; i++) {
73+
for (int j = i; j < sec.length; j++) {
74+
if(sec[i].getRating()<sec[j].getRating())
75+
{
76+
del = sec[i];
77+
sec[i]=sec[j];
78+
sec[j]=del;
79+
}
80+
}
81+
}
82+
if(sec.length>0)
83+
{
84+
return sec;
85+
}
86+
else
87+
{
88+
return null;
89+
}
90+
}
91+
}
92+
class Employee
93+
{
94+
private int Id;
95+
private String name;
96+
private String branch;
97+
private double rating;
98+
private boolean transport;
99+
100+
public Employee(int Id, String name, String branch, double rating, boolean transport)
101+
{
102+
this.Id = Id;
103+
this.name = name;
104+
this.branch = branch;
105+
this.rating = rating;
106+
this.transport = transport;
107+
}
108+
109+
public int getId()
110+
{
111+
return Id;
112+
}
113+
public void setId(int Id)
114+
{
115+
this.Id = Id;
116+
}
117+
public String getName()
118+
{
119+
return name;
120+
}
121+
public void setName(String name)
122+
{
123+
this.name = name;
124+
}
125+
public String getBranch()
126+
{
127+
return branch;
128+
}
129+
public void setBranch(String branch)
130+
{
131+
this.branch = branch;
132+
}
133+
public double getRating()
134+
{
135+
return rating;
136+
}
137+
public void setRating(double rating)
138+
{
139+
this.rating = rating;
140+
}
141+
public boolean getTransport()
142+
{
143+
return transport;
144+
}
145+
public void setTransport(boolean transport)
146+
{
147+
this.transport= transport;
148+
}
148149
}

0 commit comments

Comments
 (0)