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

In this exercise, you need to write a static “search” method that will take an a

ID: 3804687 • Letter: I

Question

In this exercise, you need to write a static “search” method that will take an array of Comparable objects and a Comparable key as parameter and it returns true if the key is present in the array, otherwise it should return false. Test your implementation with two different type of Comparable objects. One possible idea to test your code is to create two arrays, one for Monster (from exercise 4) and another for Employee (from exercise 3), then pass each one to the “search” method for testing. Save this file as SearchClient.java.

Explanation / Answer

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
#include<stdio.h>

int main()


temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;

temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;

temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}

wt[0]=0; //waiting time for initial method is zero

//calculate waiting time
for(i=1;i<n;i++)
  

avg_wt=total/n; //average waiting time
total=0;

printf(" Process Burst Time Waiting Time Turnaround Time");
for(i=0;i<n;i++)
turnaround
total+=tat[i];
printf(" P[%d] %d %d %d",p[i],bt[i],wt[i],tat[i]);
}

avg_tat=total/n; //average turnaround
printf(" Average Waiting Time=%d",avg_wt);
printf(" Average Turnaround Time=%d ",avg_tat);

return 0;
}

C++ Program


#include<iostream>

using namespace std;

int main()
{
int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat;
cout<<"Enter Total variety of Process:";
cin>>n;

cout<<" Enter Burst Time and Priority ";
for(i=0;i<n;i++)
{
cout<<" P["<<i+1<<"] ";
cout<<"Burst Time:";
cin>>bt[i];
cout<<"Priority:";
cin>>pr[i];
p[i]=i+1; //contains method variety
}

//sorting burst time, priority and method variety in ascending order mistreatment choice type
for(i=0;i<n;i++)
  

temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;

temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;

temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}

wt[0]=0; //waiting time for initial method is zero

//calculate waiting time
for(i=1;i<n;i++)
  

avg_wt=total/n; //average waiting time
total=0;

cout<<" Process Burst Time Waiting Time Turnaround Time";
for(i=0;i<n;i++)
turnaround
total+=tat[i];
cout<<" P["<<p[i]<<"] "<<bt[i]<<" "<<wt[i]<<" "<<tat[i];
}

avg_tat=total/n; //average turnaround
cout<<" Average Waiting Time="<<avg_wt;
cout<<" Average Turnaround Time="<<avg_tat;

return 0;
}
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
#include<iostream>

using namespace std;

int main()
{
int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat;
cout<<"Enter Total variety of Process:";
cin>>n;

cout<<" Enter Burst Time and Priority ";
for(i=0;i<n;i++)
{
cout<<" P["<<i+1<<"] ";
cout<<"Burst Time:";
cin>>bt[i];
cout<<"Priority:";
cin>>pr[i];
p[i]=i+1; //contains method variety
}

//sorting burst time, priority and method variety in ascending order mistreatment choice type
for(i=0;i<n;i++)
  

temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;

temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;

temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}

wt[0]=0; //waiting time for initial method is zero

//calculate waiting time
for(i=1;i<n;i++)
  

avg_wt=total/n; //average waiting time
total=0;

cout<<" Process Burst Time Waiting Time Turnaround Time";
for(i=0;i<n;i++)
turnaround
total+=tat[i];
cout<<" P["<<p[i]<<"] "<<bt[i]<<" "<<wt[i]<<" "<<tat[i];
}

avg_tat=total/n; //average turnaround
cout<<" Average Waiting Time="<<avg_wt;
cout<<" Average Turnaround Time="<<avg_tat;

return 0;
}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
#include<stdio.h>

int main()


temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;

temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;

temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}

wt[0]=0; //waiting time for initial method is zero

//calculate waiting time
for(i=1;i<n;i++)
  

avg_wt=total/n; //average waiting time
total=0;

printf(" Process Burst Time Waiting Time Turnaround Time");
for(i=0;i<n;i++)
turnaround
total+=tat[i];
printf(" P[%d] %d %d %d",p[i],bt[i],wt[i],tat[i]);
}

avg_tat=total/n; //average turnaround
printf(" Average Waiting Time=%d",avg_wt);
printf(" Average Turnaround Time=%d ",avg_tat);

return 0;
}

C++ Program


#include<iostream>

using namespace std;

int main()
{
int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat;
cout<<"Enter Total variety of Process:";
cin>>n;

cout<<" Enter Burst Time and Priority ";
for(i=0;i<n;i++)
{
cout<<" P["<<i+1<<"] ";
cout<<"Burst Time:";
cin>>bt[i];
cout<<"Priority:";
cin>>pr[i];
p[i]=i+1; //contains method variety
}

//sorting burst time, priority and method variety in ascending order mistreatment choice type
for(i=0;i<n;i++)
  

temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;

temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;

temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}

wt[0]=0; //waiting time for initial method is zero

//calculate waiting time
for(i=1;i<n;i++)
  

avg_wt=total/n; //average waiting time
total=0;

cout<<" Process Burst Time Waiting Time Turnaround Time";
for(i=0;i<n;i++)
turnaround
total+=tat[i];
cout<<" P["<<p[i]<<"] "<<bt[i]<<" "<<wt[i]<<" "<<tat[i];
}

avg_tat=total/n; //average turnaround
cout<<" Average Waiting Time="<<avg_wt;
cout<<" Average Turnaround Time="<<avg_tat;

return 0;
}
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
#include<iostream>

using namespace std;

int main()
{
int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat;
cout<<"Enter Total variety of Process:";
cin>>n;

cout<<" Enter Burst Time and Priority ";
for(i=0;i<n;i++)
{
cout<<" P["<<i+1<<"] ";
cout<<"Burst Time:";
cin>>bt[i];
cout<<"Priority:";
cin>>pr[i];
p[i]=i+1; //contains method variety
}

//sorting burst time, priority and method variety in ascending order mistreatment choice type
for(i=0;i<n;i++)
  

temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;

temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;

temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}

wt[0]=0; //waiting time for initial method is zero

//calculate waiting time
for(i=1;i<n;i++)
  

avg_wt=total/n; //average waiting time
total=0;

cout<<" Process Burst Time Waiting Time Turnaround Time";
for(i=0;i<n;i++)
turnaround
total+=tat[i];
cout<<" P["<<p[i]<<"] "<<bt[i]<<" "<<wt[i]<<" "<<tat[i];
}

avg_tat=total/n; //average turnaround
cout<<" Average Waiting Time="<<avg_wt;
cout<<" Average Turnaround Time="<<avg_tat;

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote