不了解記憶功能
public?class?view?{ ????private?static?final?String?CONTEXT="歡迎來(lái)到女神禁區(qū):\n"?+ ????????????"下面是女神禁區(qū)的功能列表:\n"?+ ????????????"[MAIN/M]:主菜單\n"?+ ????????????"[QUERY/Q]:查看全部女神的信息\n"?+ ????????????"[GET/G]:查看某位女神的詳細(xì)信息\n"?+ ????????????"[ADD/A]:添加女神信息\n"?+ ????????????"[UPDATE/U]:更新女神信息\n"?+ ????????????"[DELETE/D]:刪除女神信息\n"?+ ????????????"[SEARCH/S]:查詢女神信息(根據(jù)姓名、手機(jī)號(hào)來(lái)查詢)\n"?+ ????????????"[EXIT/E]:退出女神禁區(qū)\n"?+ ????????????"[BREAK/B]:退出當(dāng)前功能,返回主菜單"; ????private?static?final?String?OPERATION_MAIN="MAIN"; ????private?static?final?String?OPERATION_QUERY="QUERY"; ????private?static?final?String?OPERATION_GET="GET"; ????private?static?final?String?OPERATION_ADD="ADD"; ????private?static?final?String?OPERATION_UPDATE="UPDATE"; ????private?static?final?String?OPERATION_DELETE="DELETE"; ????private?static?final?String?OPERATION_SEARCH="SEARCH"; ????private?static?final?String?OPERATION_EXIT="EXIT"; ????private?static?final?String?OPERATION_BREAK="BREAK"; ????public?static?void?main(String[]?args)?throws?Exception?{ ????????System.out.println(CONTEXT); ????????Scanner?scan?=?new?Scanner(System.in); ????????Goddess?g?=?new?Goddess(); ????????ActionGoddess?ag?=?new?ActionGoddess(); ????????String?prenious?=?null; ????????int?step?=?1; ????????while(scan.hasNext()){ ????????????String?in=scan.next().toString(); ????????????if(OPERATION_EXIT.equals(in.toUpperCase())????????//退出 ????????????????????||OPERATION_EXIT.substring(0,?1).equals(in.toUpperCase())){ ????????????????System.out.println("您已成功退出女神禁區(qū)。"); ????????????????break; ????????????}else?if(OPERATION_DELETE.equals(in.toUpperCase())????//刪除女神 ????????????????????||OPERATION_DELETE.substring(0,?1).equals(in.toUpperCase()))?{ ???????????????? ????????????}else?if(OPERATION_QUERY.equals(in.toUpperCase())????//查詢?nèi)颗裥畔?????????????????????||OPERATION_QUERY.substring(0,?1).equals(in.toUpperCase())){ ????????????????List<Goddess>?goddesses?=?ag.query(); ????????????????for?(int?i=0;i<goddesses.size();i++) ????????????????????System.out.println(goddesses.get(i).toString()); ????????????}else?if(OPERATION_ADD.equals(in.toUpperCase())?????????//增加女神 ????????????????????||OPERATION_ADD.substring(0,?1).equals(in.toUpperCase()) ????????????????????||OPERATION_ADD.equals(prenious)){??? ????????????????prenious?=?OPERATION_ADD; ????????????????if(step?==?1){ ????????????????????System.out.println("請(qǐng)輸入女神的姓名:"); ????????????????}else?if(step?==?2){ ????????????????????g.setUser_name(in); ????????????????????System.out.println("請(qǐng)輸入女神的年齡:"); ????????????????}else?if(step?==?3){ ????????????????????g.setAge(Integer.valueOf(in)); ????????????????????System.out.println("請(qǐng)輸入女神的生日:(例如:yyyy-MM-dd)"); ????????????????}else?if(step==4){ ????????????????????SimpleDateFormat?sdf?=?new?SimpleDateFormat("yyyy-MM-dd"); ????????????????????try?{ ????????????????????????Date?data?=?sdf.parse(in); ????????????????????????g.setBirthday(data); ????????????????????????System.out.println("請(qǐng)輸入女神的郵箱:"); ????????????????????}?catch?(ParseException?e)?{ ????????????????????????e.printStackTrace(); ????????????????????????step?=?3; ????????????????????} ????????????????}else?if(step?==?5){ ????????????????????g.setEmail(in); ????????????????????System.out.println("請(qǐng)輸入女神的電話號(hào)碼:"); ????????????????}else?if?(step==6){ ????????????????????g.setMobile(in); ????????????????????try?{ ????????????????????????ag.addGoddess(g); ????????????????????????System.out.println("新增女神成功"); ????????????????????}?catch?(Exception?e)?{ ????????????????????????e.printStackTrace(); ????????????????????????System.out.println("新增女神失敗"); ????????????????????} ????????????????} ????????????????if?(prenious.equals(OPERATION_ADD)) ????????????????????step++; ????????????} ????????} ????} }
OPERATION_ADD.equals(prenious)? 和? prenious = OPERATION_ADD;
?? 是什么意思?記憶功能是怎么用的?
2017-08-26
在使用增加功能時(shí),將OPERATION_ADD的值賦給prenious;說(shuō)明了將值付給prenious時(shí)就是調(diào)用了增加的功能,所以進(jìn)行step++。 ? 反之如果不使用增加功能,就不會(huì)將OPERATION_ADD的值賦給prenious,所以不會(huì)增加進(jìn)行賦值