-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoo.java
93 lines (81 loc) · 2.55 KB
/
Loo.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import java.io.FileNotFoundException;
import java.io.File;
import java.util.Scanner;
public class Loo {
public static void main(String[] args) throws Exception {
var parser = new ArgumentParser(args);
String content = parser.getFilecontent();
System.out.println(content);
}
static class Position {
private int position;
Position(int position) {
this.position = position;
}
public int increment(int incrementBy) {
this.position += incrementBy;
return this.position;
}
public char currentCharacter(String data) {
if(data.length() == this.position){
return ';';
} else {
return data.charAt(this.position);
}
}
}
static class LooInterpreter {
private String data;
public LooInterpreter(String data){
this.data = data;
this.createInterpreter();
}
public int createInterpreter() {
int ascii = 0;
for(int index=0; index<this.data.length(); index++){
char character = this.data.charAt(index);
if (character == '+'){
ascii += 1;
} else if (character == '-'){
ascii -= 1;
} else if(character == '#'){
System.out.println((char)ascii);
} else if(character == ';'){
return 0;
}
}
return 0;
}
}
static class ArgumentParser {
private String[] arguments;
private int length;
public ArgumentParser(String[] arguments){
this.arguments = arguments;
this.length = this.arguments.length;
}
private String getFilename() {
if(this.length == 0) {
return "";
} else {
return this.arguments[this.length-1];
}
}
private String getFilecontent() {
try {
String data = "";
File file = new File(this.getFilename());
Scanner reader = new Scanner(file);
while (reader.hasNextLine()) {
data = reader.nextLine();
}
reader.close();
return data;
} catch (FileNotFoundException e) {
System.out.println(this.getFilename());
e.printStackTrace();
}
return "";
}
}
}