forked from bjhua/tiger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonsterGen.java
More file actions
40 lines (35 loc) · 1.02 KB
/
MonsterGen.java
File metadata and controls
40 lines (35 loc) · 1.02 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
public class MonsterGen {
public static void print(String s) {
System.out.println(s);
}
public static void usage() {
print("Monster generator.\nUsage: java MonsterGen <num>");
System.exit(1);
}
public static void main(String[] args) {
if (args.length < 1)
usage();
int num = 0;
try {
num = Integer.parseInt(args[0]);
} catch (Exception e) {
System.out.println("Expects an integer");
usage();
}
print("class Monster\n{");
print("\tstatic void main (String[] args)");
print("\t{\n\t\tSystem.out.println (new Foo().foo());");
print("\t}\n}\n");
print("class Foo\n{");
print("\tpublic int foo()");
print("\t{");
print("\t\tint sum;\n");
print("\n\t\tsum = 0;");
for (int i = 0; i < num; i++)
print("\t\tsum = sum + 1;");
print("\t\treturn sum;");
print("\t}");
print("}");
return;
}
}