Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.59 KB | None | 0 0
  1. package samples.input;   // A unique class name prefix
  2. import java.io.BufferedReader;
  3. import java.io.InputStreamReader;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6.  
  7. public class startIt  {
  8.  
  9.    private static final String errorMsg01 = new String("Invalid Input");
  10.  
  11.    private static class myPrompt {
  12.  
  13.       private String promptLine;
  14.  
  15.       public myPrompt(String s) {
  16.          this.promptLine = s;
  17.       }
  18.  
  19.       private String thisCommand() throws IOException {
  20.  
  21.          BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  22.          String thisLine = new String();
  23.  
  24.          System.out.print(this.promptLine + "> ");
  25.          thisLine = in.readLine();
  26.          return (thisLine);
  27.  
  28.       }
  29.  
  30.    }
  31.  
  32.    public static void main(String[] args) {
  33.  
  34. // Your code begins here.
  35.       int x;
  36.       myPrompt mp_obj = new myPrompt("Waiting for your input");
  37.       ArrayList<String> lst_obj = new ArrayList<String>();
  38.       String s = new String();
  39.       String s_converted = new String();
  40.  
  41.       System.out.println("--- The World's Java Console ---");
  42.       System.out.println("Type 'exit' to quit.");
  43.  
  44.       for (;;) {
  45.          try {
  46.             s = mp_obj.thisCommand();
  47.          }
  48.          catch(Exception e) {
  49.             System.out.println();
  50.             System.out.println(errorMsg01);
  51.          }
  52.          if (s == null) {
  53.             System.out.println();
  54.             System.out.println(errorMsg01);
  55.             break;
  56.          }
  57.          switch (s) {
  58.             case "":
  59.                System.out.println("You've written none.");
  60.                break;
  61.             default:
  62.                System.out.println("You've written '" + s + "'.");
  63.                break;
  64.          }
  65.          s_converted = s.toLowerCase().trim();
  66.          lst_obj.add(s);
  67.          if ((s_converted.equals("exit")) || (s_converted.equals("quit"))) {
  68.             break;
  69.          }
  70.          switch (s_converted) {
  71.             case "history":
  72.                for (x = 0; x < lst_obj.size(); x++) {
  73.                   System.out.println(lst_obj.get(x));
  74.                }
  75.                break;
  76.             case "clear":
  77.                lst_obj.clear();
  78.                System.out.println("The commands' history has been erased.");
  79.                break;
  80.          }
  81.       }
  82.  
  83.       System.out.println("Good-bye!");
  84.       System.out.println();
  85.  
  86.       System.out.println("* Copyleft 2014 Artem Efremov");
  87.       System.out.println("*");
  88.       System.out.println("* Redistribution and use in source and binary forms, with or without modification, are permitted.");
  89.  
  90.  
  91.    }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement