📄 getinput.java
字号:
package agenda;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.util.*;
//获取输入的类
public class GetInput {
public Command command = new Command();
// 命令执行函数
public void execute(String[] input) throws IOException, ParseException {
if (input[0].equalsIgnoreCase("register")) {
if (input.length == 3)// 判断命令是否符合规定格式
command.register(input[1], input[2]);
else {
System.out.println("命令的格式出错!请检查后,重新输入!\n"
+ "正确的格式应该为:register [userName] [password]");
getCommand();
}
} else if (input[0].equalsIgnoreCase("add")) {
if (input.length == 7)// 判断命令是否符合规定格式
command.add(input[1], input[2], input[3], input[4], input[5],
input[6]);
else {
System.out
.println("命令的格式出错!请检查后,重新输入!\n"
+ "正确的格式应该为:add [userName] [password] [other] [start] [end] [title]");
}
}// else if "add"
else if (input[0].equalsIgnoreCase("clear")) {
if (input.length == 3)
command.clear(input[1], input[2]);// 判断命令是否符合规定格式
else {
System.out.println("命令的格式出错!请检查后,重新输入!\n"
+ "正确的格式应该为:clear [userName] [password]");
getCommand();
}
}
else if (input[0].equalsIgnoreCase("query")) {
if (input.length == 3)
command.query(input[1], input[2]);// 判断命令是否符合规定格式
else {
System.out
.println("命令的格式出错!请检查后,重新输入!\n"
+ "正确的格式应该为: query [userName] [password] [start] [end]");
getCommand();
}
}
else if (input[0].equals("batch")){
if (input.length == 2){
batch(input[1]);
getCommand();
}
else {
System.out.println("命令的格式出错!请检查后,重新输入!\n"
+ "正确的格式应该为: batch [fileName]");
}
}
else if (input[0].equalsIgnoreCase("quit")) {
command.quit();
getCommand();
}
else if (input[0].equalsIgnoreCase("help")) {
command.help();
getCommand();
}
else {
System.out.println("输入的命令格式出错!请重新输入!想获得帮助请输入help,然后回车。");
getCommand();
}
}
// 获得命令参数
public void getCommand() throws IOException, ParseException {
boolean test;
do {
System.out.print("$");
BufferedReader in = new BufferedReader(new InputStreamReader(
System.in));
String[] input = in.readLine().split("\\s");
test = input[0].equals("6");
execute(input);
} while (!test);
}
// 欢迎信息
public void welcome() throws IOException, ParseException {
System.out.println("欢迎进入议程管理系统......" + "此系统您可以做的操作有:\n"
+ "1.注册一个新用户\n" + "2.添加一个新的会议安排\n" + "3.查询某一用户在某一时间段内的会议安排\n"
+ "4.删除某一用户的指定会议安排\n" + "5.清除某一用户的所有会议安排\n" + "6.批处理存储在文本文件中的register、add等命令\n" + "7.退出议程管理系统\n"
+ "使用命令帮助请输入help,再按回车!\n");
boolean test;
do {
System.out.print("$");
BufferedReader in = new BufferedReader(new InputStreamReader(
System.in));
String[] input = in.readLine().split("\\s");
test = input[0].equals("quit");
execute(input);
} while (!test);
}
//batch的处理函数
public void batch(String filename) throws IOException, ParseException {
ArrayList commandInFile = readFile(filename) ;
String[] temp ;
for (int i = 0;i < commandInFile.size(); i++){
temp = commandInFile.get(i).toString().split("\\s");
execute(temp);
}
}//batch
// 读取文件并且以ArrayList为返回值
@SuppressWarnings("unchecked")
public ArrayList readFile(String filename) throws IOException{
ArrayList result = new ArrayList();
try {
BufferedReader in = new BufferedReader(new FileReader("test/" + filename + ".txt"));
String find =new String();
while ((find = in.readLine()) != null){
result.add(find);
}//while
} catch (FileNotFoundException ex) {
System.out.println("找不到文件!请检查后,再输入!");
ex.printStackTrace();
}
return result;
}//readFile
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -