-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPartB.java
More file actions
41 lines (32 loc) · 1.14 KB
/
PartB.java
File metadata and controls
41 lines (32 loc) · 1.14 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
package com.employee;
public class PartB {
public void searchForAnEmployee(PermanentEmployee[] perm, int id) {
// ************************************ TODO B1 ************************************
/*
* This method should print the contact number of corresponding employee if
* present else the method should print : "Employee not in the records"
*
* Uncomment the line containing "TestYourCode.testSearchForAnEmployee(str)" to test your code
* Note : str is the contact number of the corresponding employee;
*/
String str ="";
int left = 0;
int right = perm.length - 1;
while (left <= right) {
int mid = left + (right-left) /2;
if (id == perm[mid].getId()){
str = String.valueOf(perm[mid].getContact());
}
if (id < perm[mid].getId()) {
right = mid - 1;
} else {
left = mid + 1;
}
}
System.out.println(str);
// ************************************ SOLUTION B1 BEGIN ************************************
// Uncomment below line to test your code
TestYourCode.testSearchForAnEmployee(str);
// ************************************ SOLUTION B1 END ************************************
}
}