Question

In: Computer Science

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.

Solutions

Expert Solution

JAVA code for above problem-

import java.io.*;
import java.util.Scanner;

//class that contains stub methods- linearSearch & binarySearch
public class Search{
  
//method to display menu
public void displayMenu(){
System.out.println("Please select from below:");
System.out.println("1. Linear Search");
System.out.println("2. Binary Search");
}
  
//stub method for linear search
public boolean linearSearch(String filename,String word){
  
return(true);
}
//stub method for binary search
public boolean binarySearch(String filename,String word){
  
return(true);
}
}

class GFG {
   public static void main (String[] args) {
   //scanner object
   Scanner inp = new Scanner(System.in);
   //object of Search class
   Search myobj=new Search();
   //displaying menu
   myobj.displayMenu();
  
   while(true){
   //taking user input
   System.out.println("Your Selection:");
   int option = inp.nextInt();
  
   if(option==1 || option==2){
   //taking input
   String inputFile,word;
   System.out.println("Please enter the input file to searched:");
   inputFile=inp.nextLine();
   System.out.println("Please enter the string to be searched in"+inputFile+":");
   word=inp.nextLine();
   System.out.println("Search functionality is under maintenance. Thank you for using my search program.");
  
   break;
   }
   else{
   System.out.println("Please select between option 1 or 2");
   }
   }
      
   }
}

Code-

Input and Output-


If the answer helped then please upvote.
And for any queries,please comment.


Related Solutions

JAVA FILE PROGRAM Write a contacts database program that presents the user with a menu that...
JAVA FILE PROGRAM Write a contacts database program that presents the user with a menu that allows the user to select between the following options: Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program...
in java Write a contacts database program that presents the user with a menu that allows...
in java Write a contacts database program that presents the user with a menu that allows the user to select between the following options: Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program prompts...
Write a program to show the difference between linear search and binary search. Show the input...
Write a program to show the difference between linear search and binary search. Show the input test data for your program and the output produced by your program which clearly show that binary search is faster than linear search
JAVA: Write a program to perform time conversion. The user will select from the following menu:...
JAVA: Write a program to perform time conversion. The user will select from the following menu: Hours to minutes Days to hours Minutes to hours Hours to days. Each choice has a separate method which is called when the user makes the selection. Please see the output below: Hours to minutes. 2. Days to hours. 3. Minutes to hours. 4. Hours to days. Enter your choice: 2 Enter the number of days: 5 There are 120 hours in 5 days.
Java guessing game: For this program you will use Linear Search. - Ask the user to...
Java guessing game: For this program you will use Linear Search. - Ask the user to choose between a number from 0 to 2000. - The user will guess how long the linear search will take in nanoseconds, - After the user puts in their answer, show the user the difference between the actual answer and their answer. (Example: The user puts in 5 nanoseconds. The actual time is 11 nanoseconds. The program will show 6 nanoseconds.) There should be...
Assume you need to write a Java program that uses a binary search algorithm to search...
Assume you need to write a Java program that uses a binary search algorithm to search a sorted array for a given value. 1. Write a Java pseudocode that uses recursion to accomplish the task. Here is a hint. When you are searching for a particular value in an array, there are two possible outcomes. 1) The value is found and the array index of that value is returned. 2) The value is not found and we return -1. (5...
Write a JAVA program to modify the insert and remove of a binary search tree to...
Write a JAVA program to modify the insert and remove of a binary search tree to become an AVL tree.
Problem 1: Write a Java program for traversing a Binary Search Tree in following ways: (use...
Problem 1: Write a Java program for traversing a Binary Search Tree in following ways: (use any data structure, library functions) ---------- 20 points i) Depth First Traversal: Inorder, LVR ii) Depth First Traversal: Inorder, RVL iii) Depth First Traversal: Preorder, VLR iv) Depth First Traversal: Preorder, VRL v) Depth First Traversal: Postorder, LRV vi) Depth First Traversal: Postorder, RLV No choice menu required. Sample Input (taken from keyboard, single space separated nodes as found in a complete BFS: top-down,...
java code Write a program that gives the user a menu of six choices (use integers)...
java code Write a program that gives the user a menu of six choices (use integers) to select from. The choices are circle, triangle, cone, cylinder, sphere, and quit. (The formulas are given below.) Once the figure is calculated, an informative message should be printed and the user shown the menu again, so that another choice can be made. The formulas are: Area of circle: a = 3.14 * radius * radius Area of triangle: a = ½ base *...
Write a program names EncryptDecrypt.java that has the following menu choices: Print menu and allow user...
Write a program names EncryptDecrypt.java that has the following menu choices: Print menu and allow user to choose options. The program must have a file dialogue box for text file. Output should be based on user choices. Read in a file Print the file to the console Encrypt the file and write it to the console Write out the encrypted file to a text file Clear the data in memory Read in an encrypted file Decrypt the file Write out...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT