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
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...
Related questions
Question
Please make a searching and sorting
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");](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F03735c08-776e-4821-b006-2a036c3fa4b2%2F385be180-e717-47ba-8934-e65a6ee12f67%2Fwcy1ana_processed.jpeg&w=3840&q=75)
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F03735c08-776e-4821-b006-2a036c3fa4b2%2F385be180-e717-47ba-8934-e65a6ee12f67%2Fddwbed_processed.jpeg&w=3840&q=75)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps

Recommended textbooks for you

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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

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
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY