Please make a searching and sorting algorithm for the program below. In the photos I have provide what a sorting and searching algorithm code looks like

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please make a searching and sorting algorithm for the program below. In the photos I have provide what a sorting and searching algorithm code looks like

 

java program is below

 

 

// method to search a String array for a name
public static int findName (String nameToFind, String array[])
f
int place= -1; // place is negative if not found
// loop through array
for (int i = 0; i < array.length; i++)
{
//check if name to find is equal to current array element.
if (nameToFind.equalsIgnoreCase (array [i]) == true)
{
place i // store location of name.
}
return place; // return location.
}// end findName method
String findMe; // string to store name to find
findMe JOptionPane.showInput Dialog ("Enter player to search");
int loc; // variable to store location
loc findName (findMe, playerNames); // call findName method with array and name.
if (loc < 0) // negative location means not found
{
JOptionPane.showMessageDialog (null, findMe + " not found");
}
else
(
JOptionPane.showMessageDialog (null, playerNames [loc] + " has " + playerGoals [loc] +
goals");
Transcribed Image Text:// method to search a String array for a name public static int findName (String nameToFind, String array[]) f int place= -1; // place is negative if not found // loop through array for (int i = 0; i < array.length; i++) { //check if name to find is equal to current array element. if (nameToFind.equalsIgnoreCase (array [i]) == true) { place i // store location of name. } return place; // return location. }// end findName method String findMe; // string to store name to find findMe JOptionPane.showInput Dialog ("Enter player to search"); int loc; // variable to store location loc findName (findMe, playerNames); // call findName method with array and name. if (loc < 0) // negative location means not found { JOptionPane.showMessageDialog (null, findMe + " not found"); } else ( JOptionPane.showMessageDialog (null, playerNames [loc] + " has " + playerGoals [loc] + goals");
// sort the arrays by increasing goals
// loop through the whole array
for (int i = 0; i < playerNames.length; i++)
(
//loop through to compare two elements next to
each other
for (int j = 0; j < playerNames.length 1; j++)
{
//compare one element to the next
if (playerGoals [j] > playerGoals [j+ 1])
{
// swap goals if not in increasing order
int tempGoals = playerGoals [j];
playerGoals [j] playerGoals [j+1];
playerGoals [j+1] = tempGoals;
// swap names to keep lists correct.
String tempNames playerNames [j];
playerNames [j] playerNames [j+1];
playerNames [j+1] = tempNames;
} // end if
}// end for j
}// end for i
Transcribed Image Text:// sort the arrays by increasing goals // loop through the whole array for (int i = 0; i < playerNames.length; i++) ( //loop through to compare two elements next to each other for (int j = 0; j < playerNames.length 1; j++) { //compare one element to the next if (playerGoals [j] > playerGoals [j+ 1]) { // swap goals if not in increasing order int tempGoals = playerGoals [j]; playerGoals [j] playerGoals [j+1]; playerGoals [j+1] = tempGoals; // swap names to keep lists correct. String tempNames playerNames [j]; playerNames [j] playerNames [j+1]; playerNames [j+1] = tempNames; } // end if }// end for j }// end for i
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY