Question

Write a java program that presents the user with the following menu Linear Search Binary Search...

Write a java program that presents the user with the following menu

Linear Search
Binary Search
The user can choose any of these operations using numbers 1 or 2. Once selected, the operation asks the user for an input file to be searched (the file is provided to you and is named input.txt).

If option 1 or 2 is selected, it asks the user for the search string. This is the string that the user wants the program to search in the input file. Implement two methods stubs:

1) linearSearch - takes a file and a search string as inputs, and returns a boolean signifying found or not found.

2) binarySearch - takes a file and a search string as inputs, and returns a boolean signifying found or not found.

You will develop these stubs into actual functionality in the next assignment.

Sample Output 1:

Please select from below:

1. Linear Search

2. Binary Search

Your selection: 1

Please enter the input file to searched: input.txt

Please enter the string to be searched in input.txt: RaDar

Search functionality is under maintenance. Thank you for using my search program.

---------------------------------------------------------------------------------------

Sample output 2

Please select from below:

1. Linear Search

2. Binary Search

Your selection: 90

Please select between option 1 or 2

Your selection: 2

Please enter the input file to searched: words.txt

Please enter the string to be searched in words.txt: Recoil

Search functionality is under maintenance. Thank you for using my search program.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

***Please upvote if you liked the answer***

PickYourSearch.java

import java.io.File;
import java.util.Scanner;

public class PickYourSearch {

   public static void main(String[] args) {
      
       Scanner s = new Scanner(System.in);
      
       int choice;
      
       System.out.println("Please select from below:");
       System.out.println("1.Linear Search");
       System.out.println("2.Binary Search");
      
       choice = s.nextInt();
      
       while(choice != 1 && choice != 2)
       {
           System.out.println("Your selection: " + choice);
          
           System.out.println("Please select between option 1 or 2");
          
           choice = s.nextInt();
              
       }
      
       System.out.println("Your selection: " + choice);
      
       System.out.println("Please enter the input file to search: ");
      
       String fileName = s.next();
      
       System.out.println("Please enter the string to be searched in " + fileName + ": ");
      
       String text = s.next();
      
       System.out.println("Search functionality is under maintenance. Thank you for using my search program.");
      
       s.close();
   }
  

//These are the method stubs
   public static boolean linearSearch(File f,String search_str) {
       return false;
   }
   public static boolean binarySearch(File f,String search_str) {
       return false;
   }
  
}

The screenshot of the code is attached below:-

The output is shown below :-

Output 1

Output 2

Add a comment
Know the answer?
Add Answer to:
Write a java program that presents the user with the following menu Linear Search Binary Search...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT