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);
}
}
嘿嘿
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
Linux基本操作命令
wbzjacky
2019-02-24 13:12:38
真實的模擬***綜合實驗
wbzjacky
2019-02-24 13:12:37
三層交換機的HSRP、vlan、端口聚合
wbzjacky
2019-02-24 13:12:37
HSRP和二層交換機的端口聚合、vlan
wbzjacky
2019-02-24 13:12:37
如果同事暗中傷害你,應該怎麼辦?
這個饅頭有餡
2019-02-24 13:59:08
職場中,抱怨越多的員工,越被領導瞧不起!
這個饅頭有餡
2019-02-24 13:59:08
老程序員被裁,應屆生卻能月薪 1.3 萬?這你能忍?
前端高達
2019-02-24 13:48:04
遇到到處蹭吃卻從不請客吃飯的主怎麼辦?
樑軍年
2019-02-24 13:26:35
高標準機房綜合配線安裝
wbzjacky
2019-02-24 13:12:38
IPsec ***實驗
wbzjacky
2019-02-24 13:12:37
CISCO路由AAA的Easy ***
wbzjacky
2019-02-24 13:12:37
CISCO訪問控制列表 企業網絡管理的必殺技
wbzjacky
2019-02-24 13:12:37