blob: a86601341d8def3e95eefd4ac20cc4c27af89cba (
plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/* vim: set expandtab tabstop=4 shiftwidth=4 : */
// package pkgname;
import java.io.File;
import java.util.Date;
import jargs.gnu.CmdLineParser;
public class Percolation {
public Percolation(int N) // create N-by-N grid, with all sites blocked
public void open(int i, int j) // open site (row i, column j) if it is not already
public boolean isOpen(int i, int j) // is site (row i, column j) open?
public boolean isFull(int i, int j) // is site (row i, column j) full?
public boolean percolates() // does the system percolate?
}
/**
* Class Percolation
*
* @author <john.doe@nope.com>
* @date 02/03/13
*/
public class Percolation {
/*
* print usage and exit with status 1
*/
private static void printUsage () {
System.err.println("Usage : Percolation [{-d, --debug} a_float] [ --input file_name]");
System.err.println(" debug : debug verbosity");
System.err.println(" input : path to input file");
}
/**
* application entry point
*/
public static void main (String [] args ) {
CmdLineParser parser = new CmdLineParser();
CmdLineParser.Option debug = parser.addIntegerOption('d',"debug");
CmdLineParser.Option input = parser.addStringOption("input");
try {
parser.parse(args);
} catch(CmdLineParser.OptionException e) {
System.err.println("\n"+e.getMessage());
printUsage();
System.exit(2);
}
int debugLevel = ((Integer)parser.getOptionValue(debug,new Integer(0))).intValue();
String inputFile = (String)parser.getOptionValue(input);
if(debugLevel>0){
System.out.println("Debug Trace :");
System.out.println("\t"+new Date( ) );
System.out.println("\tdebug level : "+debugLevel);
System.out.println("\texcel file : "+inputFile);
}
if(inputFile!=null && !inputFile.equals("")){
File f = new File(inputFile);
if(!f.canRead()){
System.err.println("Fatal Error : Unable to read "+inputFile);
System.exit(1);
}
}
System.exit(0);
}
}
|