Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package samples.input; // A unique class name prefix
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.io.IOException;
- import java.util.ArrayList;
- public class startIt {
- private static final String errorMsg01 = new String("Invalid Input");
- private static class myPrompt {
- private String promptLine;
- public myPrompt(String s) {
- this.promptLine = s;
- }
- private String thisCommand() throws IOException {
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- String thisLine = new String();
- System.out.print(this.promptLine + "> ");
- thisLine = in.readLine();
- return (thisLine);
- }
- }
- public static void main(String[] args) {
- // Your code begins here.
- int x;
- myPrompt mp_obj = new myPrompt("Waiting for your input");
- ArrayList<String> lst_obj = new ArrayList<String>();
- String s = new String();
- String s_converted = new String();
- System.out.println("--- The World's Java Console ---");
- System.out.println("Type 'exit' to quit.");
- for (;;) {
- try {
- s = mp_obj.thisCommand();
- }
- catch(Exception e) {
- System.out.println();
- System.out.println(errorMsg01);
- }
- if (s == null) {
- System.out.println();
- System.out.println(errorMsg01);
- break;
- }
- switch (s) {
- case "":
- System.out.println("You've written none.");
- break;
- default:
- System.out.println("You've written '" + s + "'.");
- break;
- }
- s_converted = s.toLowerCase().trim();
- lst_obj.add(s);
- if ((s_converted.equals("exit")) || (s_converted.equals("quit"))) {
- break;
- }
- switch (s_converted) {
- case "history":
- for (x = 0; x < lst_obj.size(); x++) {
- System.out.println(lst_obj.get(x));
- }
- break;
- case "clear":
- lst_obj.clear();
- System.out.println("The commands' history has been erased.");
- break;
- }
- }
- System.out.println("Good-bye!");
- System.out.println();
- System.out.println("* Copyleft 2014 Artem Efremov");
- System.out.println("*");
- System.out.println("* Redistribution and use in source and binary forms, with or without modification, are permitted.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement