Repository navigation
Expand file tree
/
Copy pathKnightsTourApp.java
More file actions
58 lines (48 loc) · 1.6 KB
/
Copy pathKnightsTourApp.java
File metadata and controls
58 lines (48 loc) · 1.6 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
// Lab 3 submitted for credit for CSCI-232
// A java implementation of the Knight's tour
// Authors: Jason Armstrong, Anthony Fopp, Kenneth Beartusk
// Instructor: Dr. Qing Yang
//
import java.io.*; // for reader and other io classes
public class KnightsTourApp {
int position;
public static void main(String[] args) throws IOException {
int size = 0;
int position = 0;
int squared = 0;
// get size of board
System.out.print("Enter board size (8 for 8x8 board) ");
size = Integer.parseInt(getString());
squared = size*size;
System.out.println("Enter the beginning square (1 to "+squared+"):");
position = Integer.parseInt(getString());
Board knightsTourBoard = new Board(size);
knightsTourBoard.getPath(position);
knightsTourBoard.printOutput();
} // end method main()
public static String getString() throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String s = br.readLine();
return s;
} // end method getString
public static String getText() throws IOException {
String outStr="", str = "";
while(true) {
str = getString();
if( str.equals("$") ){
// System.out.println(outStr); // debugging output
return outStr;
} // end if
outStr = outStr + str + "\n";
} // end while
} // end method:getText()
public static char getChar() throws IOException {
String s = getString();
return s.charAt(0);
} // end method:getChar
public static int getInt() throws IOException {
String s = getString();
return Integer.parseInt(s);
} // end method:getInt
} // end class KnightsTourApp