-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCustomScanner.java
More file actions
41 lines (34 loc) · 802 Bytes
/
CustomScanner.java
File metadata and controls
41 lines (34 loc) · 802 Bytes
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
import java.util.ArrayList;
import java.util.Scanner;
public class CustomScanner {
// Custom scanner class to run tests or cli input
Scanner scanner;
ArrayList<String> answers;
public CustomScanner(Scanner _scanner) {
scanner = _scanner;
}
public CustomScanner(ArrayList<String> _answers) {
answers = _answers;
}
public int nextInt() {
if(answers != null) {
return Integer.parseInt(answers.remove(0));
} else {
return scanner.nextInt();
}
}
public double nextDouble() {
if(answers != null) {
return Double.parseDouble(answers.remove(0));
} else {
return scanner.nextDouble();
}
}
public String next() {
if(answers != null) {
return answers.remove(0);
} else {
return scanner.next();
}
}
}