23,407
社区成员
发帖
与我相关
我的任务
分享

好难的样子 Output 太难了啊。

这个大一时候写过,lz要的话,回去给你找找。

public class StudentManageSystem {
/** StudentManager中提供的操作菜单 **/
public static void showMenus() {
String format = " %s\n";
System.out.println("----------------功能菜单------------------");
System.out.printf(format, "0. 退出管理");
System.out.printf(format, "1. 功能菜单");
System.out.printf(format, "2. 显示学生");
System.out.printf(format, "3. 查询学生");
System.out.printf(format, "4. 添加学生");
System.out.printf(format, "5. 删除学生");
System.out.printf(format, "6. 修改学生");
System.out.printf(format, "7. 读取学生");
System.out.printf(format, "8. 保存学生");
System.out.println("-------------------结束------------------");
System.out.println();
}
/** 管理学生信息 **/
public void manageStudents() throws IOException {
Scanner scanner = new Scanner(System.in);
StudentDao sd = new StudentDao();
StudentService ss = new StudentService(sd, scanner);
showMenus();
int op = -1;
while (op != 0) {
System.in.skip(System.in.available());
System.out.print("输入菜单编号: ");
op = scanner.nextInt();
scanner.nextLine(); // 吃掉输入菜单编号后无效的回车字符
try {
switch (op) {
case 0:
break;
case 1:
showMenus();
break;
case 2:
ss.showStudents();
break;
case 3:
ss.findStudents();
break;
case 4:
ss.addStudent();
break;
case 5:
ss.removeStudent();
break;
case 6:
ss.updateStudent();
break;
case 7:
ss.readStudents();
break;
case 8:
ss.saveStudents();
break;
default:
System.out.println("没有提供此项操作\n");
}
} catch (Exception e) {
System.out.println("\t" + e.getMessage() + "\n");
}
}
}