Commit 0ed24ba7 authored by trh010's avatar trh010
Browse files

started part2

parent 12eb295b
......@@ -18,16 +18,21 @@ public class AdjacencyList {
}
private ArrayList<Edge> findAndSetNeighbors(String newWord, int newHandle) {
ArrayList<Edge> neighbors = new ArrayList<Edge>();
for (int i = 0; i < adjList.size(); i++) {
Vertex testVertex = adjList.get(i);
int numDifferences = numDifferences(testVertex.getKey(), newWord);
if (2 >= numDifferences) {
testVertex.addEdge(new Edge(newHandle, numDifferences));
neighbors.add(new Edge(i, numDifferences));
}
}
return neighbors;
ArrayList<Edge> neighbors = new ArrayList<Edge>();
for (int i = 0; i < adjList.size(); i++) {
Vertex testVertex = adjList.get(i);
int numDifferences = numDifferences(testVertex.getKey(), newWord);
if (2 >= numDifferences) {
int weight = 0;
if(numDifferences == 1)
weight = 1;
else if(numDifferences == 2)
weight = 5;
testVertex.addEdge(new Edge(newHandle, weight));
neighbors.add(new Edge(i, weight));
}
}
return neighbors;
}
public int numDifferences(String a, String b) {
......
......@@ -41,7 +41,7 @@ public class Main {
* this cycle if desired. Provides the functionality necessary for Part I of
* the assignment.
*/
public void queryUser() {
public void queryUserPart1() {
boolean queryingUser = true;
Scanner in = new Scanner(System.in);
while (queryingUser) {
......@@ -78,6 +78,54 @@ public class Main {
}
in.close();
}
/**
* Queries the user for a Word, then lists the word's neighbors. Continues
* this cycle if desired. Provides the functionality necessary for Part I of
* the assignment.
*/
public void queryUserPart2() {
boolean queryingUser = true;
Scanner in = new Scanner(System.in);
while (queryingUser) {
System.out.println("Please provide the first 5 letter word: ");
String s1 = in.next();
int s1Handle = adjList.findStringHandle(s1.toUpperCase());
if (s1Handle == -1){
System.out.println("Input string " + s1
+ " is not in the dictionary");
continue;
}
String s2 = in.next();
int s2Handle = adjList.findStringHandle(s2.toUpperCase());
if (s2Handle == -1){
System.out.println("Input string " + s2
+ " is not in the dictionary");
continue;
}
//output findings
boolean validResponse = false;
while (!validResponse) {
System.out.println("Would you like to query again?:");
String s = in.next();
if (s.toUpperCase().equals("Y")
|| s.toUpperCase().equals("YES")) {
validResponse = true;
queryingUser = true;
} else if (s.toUpperCase().equals("N")
|| s.toUpperCase().equals("NO")) {
validResponse = true;
queryingUser = false;
} else {
validResponse = false;
System.out.println("Please enter a valid response: Y or N");
}
}
}
in.close();
}
/**
* Main method. Runs the program from the given input file
......@@ -89,7 +137,8 @@ public class Main {
try {
Main main = new Main();
main.createGraph(args[0]);
main.queryUser();
main.queryUserPart1();
main.queryUserPart2();
} catch (Exception e) {
System.err.println("Error! - " + e.toString());
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment