In: Computer Science
Write the following Java code into Pseudocode
import java.util.*;
public class Main
{ // Searching module
public static void score_search(int s,int score[])
{ // Initialise flag as 0
int flag=0;
// Looping till the end of the array
for(int j=0;j<10;j++)
{ // If the element is found in the array
if(s==score[j])
{ // Update flag to 1
flag=1;
}
}
// In case flag is 1 element is found
if(flag==1)
{
System.out.println("golf score found");
}
// // In case flag is 0 element is not found
else
{
System.out.println("golf score not found");
}
// Modification module
public static int[] modify(int score[],int t)
{ // Initialise new score array
int newscore[]=new int[11];
// Copying the scores to the new array
for(int k=0;k<10;k++)
{
newscore[k]=score[k];
}
// storing the new score at the last position
newscore[10]=t;
// return the new score array
return newscore;
}
// main function
public static void main(String[] args) {
// Declaring the variables
int swap,i,a,b,search,temp;
// Instantiate object of Scanner class
Scanner sc=new Scanner(System.in);
// Declaring the golf score array
int score[]=new int[10];
System.out.print("Enter the golf scores:");
// Asking user to enter the golf scores
for(i=0;i<10;i++)
{
score[i]=sc.nextInt();
}
// Sorting the golf scores in ascending order
// Looping til the end of the array
for(a=0;a<10;a++)
{ // Looping from second element till the end
for(b=a+1;b<10;b++)
{ // In case first score is greater then second
score
// Swap the golf scores
if(score[b]<score[a])
{
swap=score[a];
score[a]=score[b];
score[b]=swap;
}
}
}
System.out.print("Sorted golf
scores:");
// Printing the sorted golf
scores
for(i=0;i<10;i++)
{
System.out.print(score[i]+"
");
}
System.out.println("");
System.out.println("Enter the score
to be searched:");
// Asking user to enter the golf
score to be searched
search=sc.nextInt();
// Calling the Searching
module
score_search(search,score);
System.out.println("Enter the new
score:");
// Asking user to enter the golf
score to be added
temp=sc.nextInt();
// Printing and calling the
Modification module
System.out.println("Modified golf
score:"+Arrays.toString(modify(score,temp)));
}
}
Auto Pseudocode:
***********************************************************************************************************************************
Function Main
Declare Integer swap
Declare Integer search
Declare Integer temp
Declare Integer i
Declare Integer a
Declare Integer b
Declare Integer Array score[10]
Output "Enter the golf scores:"
For i = 0 to 9
Input score[i]
End
For a = 0 to 9
For b = a+1 to 9
If score[b]<score[a]
Assign swap = score[a]
Assign score[a] = score[b]
Assign score[b] = swap
End
End
End
Output "Sorted golf scores:"
For i = 0 to 9
Output score[i]&" "
End
Output ""
Output "Enter the score to be searched:"
Input search
Call score_search(search,score)
Output "Enter the new score:"
Input temp
Output "Modified golf score:"+modify(score,temp)
End
Function modify (Integer Array score, Integer t)
Declare Integer Array newscore[11]
Declare Integer k
For k = 0 to 9
Assign newscore[k] = score[k]
End
Assign newscore[10] = t
Return Integer[] newscore
Function score_search (Integer s, Integer Array score)
Declare Integer flag
Assign flag = 0
Declare Integer j
For j = 0 to 9
If s==score[j]
Assign flag = 1
End
End
If flag==1
Output "golf score found"
False:
Output "golf score not found"
End
End
IBO Pseudocode:
***********************************************************************************************************************************
function main()
output "Enter the golf scores:" …
loop i from 0 to 9
input score(i)
end loop
loop a from 0 to 9
loop b from a + 1 to 9
if score(b) < score(a) then
swap = score(a)
score(a) = score(b)
score(b) = swap
end If
end loop
end loop
output "Sorted golf scores:" …
loop i from 0 to 9
output score(i) + " " …
end loop
output ""
output "Enter the score to be searched:"
input search
score_search(search, score)
output "Enter the new score:"
input temp
output "Modified golf score:" + modify(score, temp)
end function
function modify(score[], t)
loop k from 0 to 9
newscore(k) = score(k)
end loop
newscore(10) = t
return newscore
end function
function score_search(s, score[])
flag = 0
loop j from 0 to 9
if s = score(j) then
flag = 1
end If
end loop
if flag = 1 then
output "golf score found"
else
output "golf score not found"
end If
end function
Output