Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

38
LINES

< > BotCompany Repo | #1000885 // Answer questions 2

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (234L/2K/7K).

1  
!747
2  
3  
m {
4  
  static S question = "Is port 80 open?";
5  
  
6  
  static class ThePortOracle {
7  
    static S isPort_open(S s) {
8  
      int port = parseInt(s);
9  
      print("I'll check port " + port + "..."); 
10  
      boolean b = isPortOpen(port);
11  
      return b ? "Yes, it is open!" : "No, it is not open.";
12  
    }
13  
  }
14  
  
15  
  static S answerQuestion(S question) {
16  
    L<S> tok = parse(question);
17  
    S[] m = match2(parse("is port * open"), tok);
18  
    if (m != null) return ThePortOracle.isPort_open(m[0]);
19  
    return unknown(question);
20  
  }
21  
  
22  
  static S unknown(S question) {
23  
    return "? Unknown question: " + question;
24  
  }
25  
26  
  p {
27  
    if (args.length != 0)
28  
      question = join(" ", args);
29  
    print("Q: " + question);
30  
    
31  
    S answer = answerQuestion(question);
32  
    print("A: " + answer);
33  
  }
34  
  
35  
  static L<S> parse(S s) {
36  
    return tokensToLowerCase(dropPunctuation(javaTokPlusPeriod(s)));
37  
  }
38  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1000885
Snippet name: Answer questions 2
Eternal ID of this version: #1000885/1
Text MD5: 7e87bd40a6db5675c3e2bcc4881cf119
Transpilation MD5: 5d1fd4f6f5668fbb978d173babecd3ea
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-09-05 15:14:33
Source code size: 922 bytes / 38 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 725 / 754
Referenced in: [show references]