-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPartA.java
More file actions
89 lines (68 loc) · 2.65 KB
/
PartA.java
File metadata and controls
89 lines (68 loc) · 2.65 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
package com.employee;
public class PartA {
public void createTeams(PermanentEmployee[] perm) {
// ************************************ TODO A1 ************************************
/*
* This method should print the even and odd teams along with their respective captains.
*
* If there are less than 11 players in any of the team, Print
* "Teams cannot be formed"
*
* Uncomment the line containing "TestYourCode.testTeams(evenTeam, oddTeam)" to test your code
* Note : evenTeam and OddTeam are integer arrays containing employee Ids of evenTeam and oddTeam respectively.
*/
int[] evenTeam = new int[11];
int[] oddTeam = new int[11];
int x = 0;
int y = 0;
for (int i = perm.length - 1; i > -1 ; i--) {
if (x == 11 && y == 11) break;
if (x < 11 && perm[i].getId() % 2 == 0) {
evenTeam[x] = perm[i].getId();
x++;
} else if (y < 11){
oddTeam[y] = perm[i].getId();
y++;
}
}
for (int i = 0; i < 11; i++) {
System.out.print(evenTeam[i] + " ");
}
System.out.println("\n" + evenTeam[5]);
for (int i = 0; i < 11; i++) {
System.out.print(oddTeam[i] + " ");
}
System.out.println("\n" + oddTeam[5]);
// ************************************ SOLUTION A1 BEGIN ************************************
// Uncomment the line below to test your code
TestYourCode.testTeams(evenTeam, oddTeam);
// ************************************ SOLUTION A1 END************************************
}
public void findTwoBestPerformers(PermanentEmployee[] perm) {
// ************************************ TODO A2 ************************************
/*
* This method should print Employee ID, Name and Rating of the two Employees
* who have the maximum Ratings (100 being the best).
*
* Uncomment the line containing TestYourCode.testTwoBestPerformers(bestPerformer.getId(), secondPerformer.getId())
* to test your code
*/
PermanentEmployee bestPerformer = perm[0];
PermanentEmployee secondPerformer = perm[0];
for (int i = 1; i < perm.length; i++) {
if(bestPerformer.getRating() < perm[i].getRating()) {
secondPerformer = bestPerformer;
bestPerformer = perm[i];
}
else if(secondPerformer.getRating() < perm[i].getRating()){
secondPerformer = perm[i];
}
}
System.out.println(bestPerformer.getId());
System.out.println(secondPerformer.getId());
//************************************ SOLUTION A2 BEGIN ************************************
// Uncomment the line below to test your code
TestYourCode.testTwoBestPerformers(bestPerformer.getId(), secondPerformer.getId());
// ************************************ SOLUTION A2 END ************************************
}
}