Build two classes (LinearSearch and BinarySearch) that inherit from the provided
ID: 3626548 • Letter: B
Question
Build two classes (LinearSearch and BinarySearch) that inherit from the provided parent class SearchAlgorithm. Each of these classes will implement only one public method that facilitates the appropriate search over an array of Strings. Also, you will need to build one exception class (10 lines of code or less) that services these two searches in the event the item isn’t found in the String array.
Note: We have to use the direction and classes explained for assignment #6 in following link:
http://courses.washington.edu/css162/rnash/assign.html
Use these classes from the link mentioned on top:Assignment 6 , WumpusHunter.java , MountainCave.java , MountainFactory.java , BinaryMountainFactory.java ,
TertiaryMountainFactory.java , WMDriver.java -->
Explanation / Answer
i hope this will help u these are the binary class and the linear class each alone // Program to implement Binary Search Method //Using BufferedReader class //Using main() import java.io.*; public class BinarySearch { public static void main(String args[]) throws IOException { //Declaring variables BufferedReader obj=new BufferedReader(new InputStreamReader(System.in)); int arr[]={2,3,8,12,15,34,45,56,57,62,67,89,90}; // 13 integers int low=0, up=12; //lower and upper bound of array int mid=0,n; boolean flag=false; //Taking input System.out.println(” Enter the number to be searched “); n=Integer.parseInt(obj.readLine()); //Starting Search while(lowarr[mid]) low=mid+1; else up=mid-1; }//end while //if n is not present if(flag==false) System.out.println(n+ ” is not in the list”); }// method ends }// class ends ----------------- // Program to implement Linear Search // Using Scanner class import java.util.Scanner; public class LinearSearch{ public void search(){ //Declaring variables boolean flag=false; String name[]={“Raghav”, “Rishabh”, “Akshay”, “Taptej”, “Shubham’, “Parul”, “Iti”}; String phone[]={“9335500667?, “9897709876?, “9192875786?, “93345663456?,”9193445678?, “9897484860?, “9667784390?}; Scanner scan=new Scanner(System.in); //taking input System.out.print(“Enter the name to be searched: ”); String s= new next(); int len=name.length; //Searching name in the list for(int x=0;xRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.