Commit 5e8e234d authored by trh010's avatar trh010
Browse files

Main framework completed

parent 5ebfe2a4
......@@ -68,6 +68,19 @@ public class AdjacencyList {
return out.toString();
}
public Vertex getVertexFromHandle(int handle) {
return adjList.get(handle);
}
public int findStringHandle(String s) {
for (int i = 0; i < adjList.size(); i++) {
if (s.equals(adjList.get(i).getKey()))
return i;
}
return -1;
}
public String toString() {
StringBuffer out = new StringBuffer();
out.append("Handle Key | Neighbors \n");
......
......@@ -29,13 +29,48 @@ public class Main {
adjList.addNode(in.next());
}
in.close();
System.out.println(adjList.toString());
// System.out.println(adjList.toString());
} catch (FileNotFoundException e) {
System.err.println("Error in opening the file: " + path
+ ". Please check the file path.");
}
}
public void queryUser() {
boolean queryingUser = true;
Scanner in = new Scanner(System.in);
while (queryingUser) {
System.out.println("Please provide a 5 letter word: ");
String s = in.next();
int handle = adjList.findStringHandle(s.toUpperCase());
if (handle == -1)
System.out.println("Input string " + s
+ " is not in the dictionary");
else
System.out.println(adjList.neighborsToString(adjList
.getVertexFromHandle(handle)));
boolean validResponse = false;
while (!validResponse) {
System.out.println("Would you like to query again?:");
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
*
......@@ -46,6 +81,7 @@ public class Main {
try {
Main main = new Main();
main.createGraph(args[0]);
main.queryUser();
} catch (Exception e) {
System.err.println("Error! - " + e.toString());
}
......
Markdown is supported
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