嘿嘿

   try {
             while (true) {
                 System.out.println("1.插入  2.删除  3.搜索 4.显示所有记录 5.退出");
                 System.out.println("请选择功能号");
                 BufferedReader br = new BufferedReader(new
                         InputStreamReader(System.in));
                 choice = (char) br.read();
                 switch (choice) {
                 case '1':
                     try {
                         System.out.println("输入学生 ID");
                         BufferedReader br1 = new BufferedReader(new
                                 InputStreamReader(System.in));
                         id = Integer.parseInt(br1.readLine());
                         System.out.println("输入学生姓名");
                         name = br1.readLine();
                         System.out.println();
                         System.out.println("输入住址");
                         address = br1.readLine();
                         System.out.println();
                         System.out.println("输入课程");
                         course = br1.readLine();
                         System.out.println();
                         home.create(new Integer(id), name, address, course);//添加代码
                         System.out.println("记录已成功添加");
                         System.out.println();
                     } catch (Exception error) {
                         System.out.println("错误!");
                         System.out.println();
                     }
                     break;
 
 
                 case '2':
                     System.out.println();
                     System.out.println("输入要删除记录的学生 ID");
                     BufferedReader br12 = new BufferedReader(new
                             InputStreamReader(System.in));
                     id = Integer.parseInt(br12.readLine());
                     home.remove(new Integer(id));//删除
                     System.out.println();
                     System.out.println("记录已成功删除");
                     break;
 
                 case '3':
                     try {
                         System.out.println();
                         System.out.println("输入学生 ID");
                         BufferedReader br1 = new BufferedReader(new
                                 InputStreamReader(System.in));
                         input = Integer.parseInt(br1.readLine());
                         remote = home.findByPrimaryKey(new Integer(input));
                         System.out.println();
                         System.out.println("学生的详细信息为:");
                         System.out.println();
                         System.out.println("学生 ID:" + remote.getStudentId());
                         System.out.println("学生姓名:"
                                            +
                                            fomart(remote.getStudentName()));
                         System.out.println("住址:"
                                            +
                                            fomart(remote.getAddress()));
                         System.out.println("课程:" + remote.getCourse());
                         System.out.println();
                     } catch (ObjectNotFoundException error) {
                         System.out.println("无此学生");
                         System.out.println();
                     }
                     break;
 
                 case '4':
 
                     java.util.Iterator display
                             = home.findAllStudents().
                                                  iterator();
                     System.out.println();
                     System.out.println("学生 ID     学生姓名          住址        课程");
                     System.out.println(
                             "-------------------"
                             + "----------------------------------------");
 
//                     Integer i= new Integer(0);
                     Integer j = new Integer(0);
                     int i = 0;
                     while (display.hasNext()) {
                         StudentDetailRemote records = (StudentDetailRemote)
                                 display.next();
                         i = i + records.getStudentId().intValue();
                         System.out.print(records.getStudentId());
                         System.out.print("              "
                                          +
                                          fomart(records.getStudentName()));
                         System.out.print(" " + fomart(records.getAddress()));
                         System.out.print("     " + records.getCourse());
                         System.out.println();
                     }
                     System.out.println(i);
                     System.out.println(
                             "-------------------"
                             + "----------------------------------------");
                     System.out.println();
                     break;
                 case '5':
                     System.out.println("应用程序已终止");
                     System.exit(0);
                     break;
                 default:
                     System.out.println("无效选项");
                 }
             }
 
         } catch (Exception error) {
             System.out.println(error);
         }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章