In this post, you will get the solution to the first problem of Capgemini ADAPT Sprint 1 – JBR-CS5A-L2-1-SortByCustomerId.
Note: The solutions are provided for learning purposes only.
Sprint 1 – Problem 3: JBR-CS5A-L2-1-SortByCustomerId:
Problem Description:
Create a program with a multi-dimensional array to store the customerDetails (customerId, name, address) array. This program should sort the customer based on the customer id.
Sample Input:
1001
Raj
Chennai
1008
Akshay
Pune
1002
Simrath
Amristar
1204
Gaurav
Delhi
1005
Ganesh
Chennai
Sample Output:
1001
Raj
Chennai
1002
Simrath
Amristar
1005
Ganesh
Chennai
Execution Time Limit:
10 seconds
The solution to JBR-CS5A-L2-1-SortByCustomerId:
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Source{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
String[][]s = new String [5][3];
for(int i = 0; i < 5; i++)
s[i][0] = "0";
for(int i = 0; i < 5; i++)
for(int j = 0; j < 3; j++)
if(sc.hasNextLine())
s[i][j] = sc.nextLine();
for(int i = 0; i < 4; i++){
for(int j = 0; j < 4-i; j++){
int a = Integer.parseInt(s[j][0];
int b = Integer.parseInt(s[j+1][0]);
if(a>b)
swap(s, j);
}
}
for(int i = 0; i < 5; i++)
for(int j = 0; j < 3; j++)
System.out.println(s[i][j]);
}
private static void swap(String[][] a, int i){
for(int j = 0; j < 3; j++){
String temp = a[i][j];
a[i][j] = a[i+1][j];
a[i+1][j] = temp;
}
}
}
- Capgemini ADAPT Sprint 1 Bus Reservation System – DisplayCustomerInAscendingOrder Problem Solution
- Capgemini ADAPT Sprint 1 Bus Reservation System – DisplayCustomerByFirstName Problem Solution
- Capgemini ADAPT Sprint 1 Bus Reservation System – SortByCustomerId Problem Solution
- Capgemini ADAPT Sprint 1 Solution Java | LSAByCustomerName Problem Solution


