Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
trh010
cs311_final_project
Commits
5e8e234d
Commit
5e8e234d
authored
Apr 15, 2014
by
trh010
Browse files
Main framework completed
parent
5ebfe2a4
Changes
2
Hide whitespace changes
Inline
Side-by-side
CS311_final_project/src/main/AdjacencyList.java
View file @
5e8e234d
...
...
@@ -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"
);
...
...
CS311_final_project/src/main/Main.java
View file @
5e8e234d
...
...
@@ -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
());
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment