-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathShell.java
85 lines (73 loc) · 2.47 KB
/
Shell.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
import java.util.List;
import java.util.Arrays;
import java.util.Scanner;
import java.util.ArrayList;
class Student {
static boolean in(List<Integer> vet, int x) {
return false;
}
static int indexOf(List<Integer> vet, int x) {
return 0;
}
static int findIf(List<Integer> vet) {
return 0;
}
static int minElement(List<Integer> vet) {
return 0;
}
static int findMinIf(List<Integer> vet) {
return 0;
}
public static void main(String[] args) {
System.out.println("Rodando o arquivo do estudante");
}
}
public class Shell {
public static void main(String[] _args) {
while (true) {
String line = scanner.nextLine();
System.out.println('$' + line);
var par = line.split(" ");
var cmd = cmd;
if ("end".equals(cmd)) {
break;
}
else if ("in".equals(cmd)) {
var array = strToVet(par[1]);
var value = Integer.parseInt(par[2]);
var result = Student.in(array, value);
System.out.println(result ? "true" : "false");
}
else if ("index_of".equals(cmd)) {
var array = strToVet(par[1]);
var value = Integer.parseInt(par[2]);
var result = Student.indexOf(array, value);
System.out.println("" + result);
}
else if ("find_if".equals(cmd)) {
var result = Student.findIf(strToVet(par[1]));
System.out.println("" + result);
}
else if ("min_element".equals(cmd)) {
var result = Student.minElement(strToVet(par[1]));
System.out.println("" + result);
}
else if ("find_min_if".equals(cmd)) {
var result = Student.findMinIf(strToVet(par[1]));
System.out.println("" + result);
}
else {
System.out.println("fail: comando invalido");
}
}
}
public static List<Integer> strToVet(String s) {
if(s.length() == 2) return new ArrayList<>();
List<String> parts = Arrays.asList(s.substring(1, s.length() - 1).split(","));
List<Integer> result = new ArrayList<>();
for (String part : parts)
result.add(Integer.parseInt(part.trim()));
return result;
}
static Scanner scanner = new Scanner(System.in);
}