Question: Q2. Write a Java program that has two classes, as follows: Class Hws 02 YourStudentld Demo You will do the following in the main method

Q2. Write a Java program that has two classes, as follows: Class Hws 02 YourStudentld Demo You will do the following in the main method of this class: Open a given txt file (you may hard code the filename) containingnnames, and read and Create an object of SortAndSearch class (described below) and use the sort and search Print The given namiss" if the name is found, else "The given nameis not store these names into a Suing aray -Ask user to enter a name to search in the array methods on this object. The search method returns true if the name exits in the list, elhe returns false, found", if the name doesn't exist in the list Class SrtAndSearch, with the following properties: -one instance field, i.e. Suing array constructor that sets the String array field with the input String array -method 1 (for sorting) sorts the String array (using Selection sort algorithm), and returns the sorted array method 2 (for searching) accepts the following ar gument: a specific name to search in the sorted array (using Binary search algorithm), and returns true if the given name exists, otherwise retuas false Sample output is as below If the txt file contains the following names (show the working of your program with atleast in the tt fle): names John Mary Ravi Brandon Stephane Abdul Ram And the user enters the following name to search Enter the name to search: Mark The sorted array will be as follows Abdul Brandon John Mark Ram Ravi After the search is performed, the program will print The given name "Mark" exists
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
