-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSequentialTester_gonz.java
More file actions
58 lines (55 loc) · 1.74 KB
/
SequentialTester_gonz.java
File metadata and controls
58 lines (55 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//Brandon Gonzalez
//Searching Assign 1
/**
* The program runs pretty well.
* The only thing i ran into was a few missing semicolons and for some reasons
* I made the find function static because I wasnt paying attention
* Used about 20 test cases and none failed :D
*/
import java.util.Scanner;
/**
* Sequential Tester has the moves like jagger.
* Scans for the teacher name and then attempts to ifnd the teacher
* in the array
*/
public class SequentialTester_gonz {
public static void main(String[] args) {
SequentialFinder finder = new SequentialFinder();
Scanner myScanner = new Scanner(System.in);
System.out.println("Please enter the teacher you want to search for: ");
String input = myScanner.nextLine();
int x = finder.find(getNames(), input);
if(x == -1)
System.out.println("Teacher not found!");
else
System.out.println( getNames()[x] + " was found @ " + x);
}
public static String[] getNames() {
String[] names = { "Adams", "Amarillas", "Baxter", "Duong","Giraudo",
"Gonzalez", "Hansbrough", "Kniffin", "Lindemann",
"Lum", "Mathurin", "McCullough", "Molina",
"Reyerson", "Ward", "Wolf", "Wong", "Zabinski" };
return names;
}
}
interface Finder {
public int find(String[] hayStack, String needle);
}
/**
* Linear Search algorithm class stuff
* Implements finder which implements a linear search alg
*/
class SequentialFinder implements Finder {
/**
* Returns the index of the object if found.
* If not found, returns -1
*/
public int find(String[] hayStack, String needle) {
int x = -1;
for(int i = 0; i < hayStack.length; i++) {
if (hayStack[i].equals(needle))
x = i;
}
return x;
}
}