Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CS2308 Programming Project 1: The Searching Techniques Reference: Chapter sectio

ID: 3744898 • Letter: C

Question

CS2308 Programming Project 1: The Searching Techniques Reference: Chapter sections 8.1 and 8.2 (earching) And Progr 8-2, 8-3 as good examples a. Create three array of 12+ students records includtng ID's, student names, and the corresponding e-mail addresses,- student ID's are sorted in order b. sequential search five ID's which are from the sorted array and a c. Binary Search five ID's which are from the sorted array and a 6th d. Execution and output: 6th ID which is not from the array. ID which is not from the array 1. Display the original sorted array of student records. 2. Display the sequential search result of student records 3. Display the binary search result of student records. e. Turn in source programs and the outputs of item (e) f. The following should apply to all assignments during the semester. Turn in with hard copy and must be professional and the turn in should include the source Program, and the displayed outputs as described above. Proper messages in the output are required to indicate the execution and different outputs. Turn in all assignments in class. It will have late penalty 10% if your turn in 30 minutes after elass begins and before class of next assignment due day. g. Anything not mentioned in this assignment, you are free to do whatever you desire. No need to ask questions

Explanation / Answer

SearchingTechniques.java

public class SearchingTechniques {

public static void main(String[] args) {

  

//Declaring and initializing an array

int id[]={2,4,5,6,8,10,15,16,18,20,23,25,27};

String names[]={"John","James","Smith","Milly","Joe","Dany","Sachin","Phani","Ben","Thomas","Ken","Anil","Stuart"};

String email[]={"johnymail.com","jamesymail.com","smithymail.com","millyymail.com","joeymail.com",

"danyymail.com","sachinymail.com","phaniymail.com","benymail.com","thomasymail.com",

"kenymail.com","anilymail.com","startymail.com"};

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

  

System.out.println("Sequential Search :");

for(int i=0;i<6;i++)

{

//Getting the input entered by the user

System.out.print(" Enter id:");

int sId=sc.nextInt();

int indx=sequentialSearch(id,sId);

if(indx==-1)

{

System.out.println(sId+" not found.");

}

else

{

System.out.println("Student name :"+names[indx]);

System.out.println("Email :"+email[indx]);

}

}

System.out.println(" Binary Search :");

for(int i=0;i<6;i++)

{

//Getting the input entered by the user

System.out.print(" Enter id:");

int sId=sc.nextInt();

int indx=binarySearch(id,sId);

if(indx==-1)

{

System.out.println(sId+" not found.");

}

else

{

System.out.println("Student name :"+names[indx]);

System.out.println("Email :"+email[indx]);

}

}

}

/*

* method implementation which search for the number in the array using

* binary search algorithm

*

* @Params array and number

*

* @return position

*/

private static int binarySearch(int[] arr, int num) {

int first = 0, mid = 0;

int last = arr.length - 1;

while (first <= last) {

mid = (first + last) / 2;

if (num == arr[mid])

return mid;

if (num < arr[mid])

last = mid - 1;

else

first = mid + 1;

}

return -1;

}

private static int sequentialSearch(int[] id, int sId) {

for(int i=0;i<id.length;i++)

{

if(sId==id[i])

return i;

}

return -1;

}

}

________________

Output:

Sequential Search :

Enter id:2
Student name :John
Email :johnymail.com

Enter id:4
Student name :James
Email :jamesymail.com

Enter id:8
Student name :Joe
Email :joeymail.com

Enter id:10
Student name :Dany
Email :danyymail.com

Enter id:16
Student name :Phani
Email :phaniymail.com

Enter id:22
22 not found.

Binary Search :

Enter id:2
Student name :John
Email :johnymail.com

Enter id:4
Student name :James
Email :jamesymail.com

Enter id:8
Student name :Joe
Email :joeymail.com

Enter id:10
Student name :Dany
Email :danyymail.com

Enter id:15
Student name :Sachin
Email :sachinymail.com

Enter id:26
26 not found.


___________Thank You