In this post, you will get the solution to the first problem of Capgemini ADAPT Sprint 1 – JBR-CS5A-L2-2-BSAByCustomerId.

Note: The solutions are provided for learning purposes only.

## Sprint 1 – Problem 5: JBR-CS5A-L2-3-BSAByCustomerId:

Write a program to search the customer based on the customer’s Id using Binary Search Algorithm.

This program should print “No Record Found” if the Id is not available in the given array.

Note: Use binary search algorithm

1005

1005

Ganesh

Chennai

2345

No Record Found

10 seconds

## The solution to JBR-CS5A-L2-3-BSAByCustomerId:

```import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Source{
static class Customer{
int id;
String name;
String city;

public Customer(int id, String name, String city){
this.id = id;
this.name = name;
this.city = city;
}
}
public static void main(String[] args){
Customer[] customers = new Customer[5];

customers[0] = new Customer(1001, "Raj", "Chennai");
customers[1] = new Customer(1002, "Simrath", "Amristar");
customers[2] = new Customer(1005, "Ganesh", "Chennai");
customers[3] = new Customer(1008, "Akshay", "Pune");
customers[4] = new Customer(1204, "Gaurav", "Delhi");

Scanner sc = new Scanner(System.in);

int key = sc.nextInt();
sc.close();

int first = 0;
int last = customers.length-1;
int mid = (first+last)/2;
while(first<=last){
if(customers[mid].id<key){
fid = mid + 1;
}else if(customers[mid].id == key){
Customer customer = customers[mid];
System.out.println(customer.id);
System.out.println(customer.name);
System.out.println(customer.city);
break;
} else {
last = mid - 1;
}
mid = (first+last)/2;
}
if(first>last){
System.out.println("No Record Found");
}
}
}

```