-
Notifications
You must be signed in to change notification settings - Fork 0
/
MazeGenerator.java
48 lines (43 loc) · 1.24 KB
/
MazeGenerator.java
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
/*
* c3309266
* Akshata Dhuraji
* COMP2230 Assignment
*/
import java.io.IOException;
import java.io.PrintWriter;
public class MazeGenerator {
/**
* Main driver method of MazeGenerator app
* @param args command line arguments
*/
public static void main(String[] args) {
// validating number of command line arguments
if (args.length != 3) {
throw new IllegalArgumentException("Illegal number of command line arguments. 3 arguments expected");
}
// validating and parsing maze height
int height;
try {
height = Integer.parseInt(args[0]);
}
catch (NumberFormatException ignored) {
throw new IllegalArgumentException("Can not parse maze height. Positive integer expected");
}
// validating and parsing maze width
int width;
try {
width = Integer.parseInt(args[1]);
}
catch (NumberFormatException ignored) {
throw new IllegalArgumentException("Can not parse maze width. Positive integer expected");
}
// generating maze with given parameters and writing it to file with given filename
try (PrintWriter pw = new PrintWriter(args[2])) {
Maze maze = new Maze(height, width);
pw.println(maze);
}
catch (IOException ignored) {
throw new IllegalArgumentException("Can not open output file");
}
}
}