Question

In: Computer Science

Write the following Java code into Pseudocode import java.util.*; public class Main { // Searching module...

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)));
   }
}

Solutions

Expert Solution

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


Related Solutions

I need a java flowchart diagram for the following code: import java.util.*; public class Main {...
I need a java flowchart diagram for the following code: import java.util.*; public class Main {    public static void main(String[] args) {    Scanner sc=new Scanner(System.in);           System.out.print("Enter the input size: ");        int n=sc.nextInt();        int arr[]=new int[n];        System.out.print("Enter the sequence: ");        for(int i=0;i<n;i++)        arr[i]=sc.nextInt();        if(isConsecutiveFour(arr))        {        System.out.print("yes the array contain consecutive number:");        for(int i=0;i<n;i++)        System.out.print(arr[i]+" ");   ...
WRITE THIS JAVA CODE IN PSEUDOCODE!! import java.util.Scanner; public class License { public static void main(String[]...
WRITE THIS JAVA CODE IN PSEUDOCODE!! import java.util.Scanner; public class License { public static void main(String[] args) { char correctAnswers[] = {'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B', 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A'}; char userAnswers[] = new char[correctAnswers.length]; Scanner scanner = new Scanner(System.in); for (int i = 0; i < userAnswers.length; i++) { String answer = ""; System.out.printf("Question #%d. Enter your answer( A, B, C or D): ", i + 1); do...
Convert this java code from hashmap into arraylist. import java.io.*; import java.util.*; public class Solution {...
Convert this java code from hashmap into arraylist. import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); HashMap labs = new HashMap(); while (true) { System.out.println("Choose operation : "); System.out.println("1. Create a Lab"); System.out.println("2. Modify a Lab"); System.out.println("3. Delete a Lab"); System.out.println("4. Assign a pc to a Lab"); System.out.println("5. Remove a pc from a Lab"); System.out.println("6. Quit"); int choice = sc.nextInt(); String name=sc.nextLine(); switch (choice) { case 1:...
// problem2.java import java.util.*; public class problem_a { public static void main(String[] args) { // test...
// problem2.java import java.util.*; public class problem_a { public static void main(String[] args) { // test the smallest method System.out.print("smallest(1, 0, 2) -> "); System.out.println( smallest(1, 0, 2) ); // test the average method System.out.print("average(95, 85, 90) -> "); System.out.println( average(95, 84, 90) ); } // end main /* * smallest(double, double, double) -> double * * method is given 3 numbers, produces the smallest of the three * * examples: * smallest(1, 0, 2) -> 0.0 */ public static...
Add comments to the following code: PeopleQueue.java import java.util.*; public class PeopleQueue {     public static...
Add comments to the following code: PeopleQueue.java import java.util.*; public class PeopleQueue {     public static void main(String[] args) {         PriorityQueue<Person> peopleQueue = new PriorityQueue<>();         Scanner s = new Scanner(System.in);         String firstNameIn;         String lastNameIn;         int ageIn = 0;         int count = 1;         boolean done = false;         System.out.println("Enter the first name, last name and age of 5 people.");         while(peopleQueue.size() < 5) {             System.out.println("Enter a person");             System.out.print("First Name: ");             firstNameIn...
CONVERT CODE FROM JAVA TO C# PLEASE AND SHOW OUTPUT import java.util.*; public class TestPaperFolds {...
CONVERT CODE FROM JAVA TO C# PLEASE AND SHOW OUTPUT import java.util.*; public class TestPaperFolds {    public static void main(String[] args)    {        for(int i = 1; i <= 4; i++)               //loop for i = 1 to 4 folds        {            String fold_string = paperFold(i);   //call paperFold to get the String for i folds            System.out.println("For " + i + " folds we get: " + fold_string);        }    }    public static String paperFold(int numOfFolds)  ...
UML Diagram for this java code //java code import java.util.*; class Message { private String sentence;...
UML Diagram for this java code //java code import java.util.*; class Message { private String sentence; Message() { sentence=""; } Message(String text) { setSentence(text); } void setSentence(String text) { sentence=text; } String getSentence() { return sentence; } int getVowels() { int count=0; for(int i=0;i<sentence.length();i++) { char ch=sentence.charAt(i); if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U') { count=count+1; } } return count; } int getConsonants() { int count=0; for(int i=0;i<sentence.length();i++)...
I'm getting an error for this code? it won't compile import java.util.*; import java.io.*; public class...
I'm getting an error for this code? it won't compile import java.util.*; import java.io.*; public class Qup3 implements xxxxxlist {// implements interface    // xxxxxlnk class variables    // head is a pointer to beginning of rlinked list    private node head;    // no. of elements in the list    // private int count; // xxxxxlnk class constructor    Qup3() {        head = null;        count = 0;    } // end Dersop3 class constructor   ...
In java. Please explain. Consider the following program: } import java.util.*; public class Chapter7Ex12 { static...
In java. Please explain. Consider the following program: } import java.util.*; public class Chapter7Ex12 { static Scanner console = new Scanner(System.in); public static void main(String[] args) { double num1; double num2; System.out.print("Enter two integers: "); num1 = console.nextInt(); num2 = console.nextInt(); System.out.println(); if (num1 != 0 && num2 != 0) System.out.printf("%.2f\n", Math.sqrt(Math.abs(num1 + num2 + 0.0))); else if (num1 != 0) System.out.printf("%.2f\n", Math.floor(num1 + 0.0)); else if (num2 != 0) System.out.printf("%.2f\n",Math.ceil(num2 + 0.0)); else System.out.println(0); }} a. What is the...
Add code to the Account class and create a new class called BalanceComparator. import java.util.*; public...
Add code to the Account class and create a new class called BalanceComparator. import java.util.*; public final class Account implements Comparable {     private String firstName;     private String lastName;     private int accountNumber;     private double balance;     private boolean isNewAccount;     public Account(             String firstName,             String lastName,             int accountNumber,             double balance,             boolean isNewAccount     ) {         this.firstName = firstName;         this.lastName = lastName;         this.accountNumber = accountNumber;         this.balance = balance;         this.isNewAccount = isNewAccount;     }     /**      * TO DO: override equals      */     @Override     public boolean equals(Object other) {...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT