forked from rchatley/BasicWebApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryProcessor.java
More file actions
53 lines (38 loc) · 1.43 KB
/
QueryProcessor.java
File metadata and controls
53 lines (38 loc) · 1.43 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
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.develogical;
import java.util.Arrays;
public class QueryProcessor {
public String process(String query) {
if (query.toLowerCase().contains("shakespeare")) {
return "William Shakespeare (26 April 1564 - 23 April 1616) was an " +
"English poet, playwright, and actor, widely regarded as the greatest " +
"writer in the English language and the world's pre-eminent dramatist.";
}
if (query.toLowerCase().contains("large")){
query.replaceAll("%20", "");
query.replaceAll("[^0-9]+", " ");
List<Int> x = Arrays.asList(query.trim().split(" "));
return x.max();
}
if (query.toLowerCase().contains("plus")){
query.replaceAll("%20", "");
query.replaceAll("[^0-9]+", " ");
List<Int> x = Arrays.asList(query.trim().split(" "));
int sum = 0;
for(int i = 0; i < x.size(); i++){
sum += x.get(i);
}
return sum;
}
if (query.toLowerCase().contains("multip")){
query.replaceAll("%20", "");
query.replaceAll("[^0-9]+", " ");
List<Int> x = Arrays.asList(query.trim().split(" "));
int sum = 1;
for(int i = 0; i < x.size(); i++){
sum = sum * x.get(i);
}
return sum;
}
return "";
}
}