《java案例自动售货机》由会员分享,可在线阅读,更多相关《java案例自动售货机(6页珍藏版)》请在金锄头文库上搜索。
1、packageLevelSecond;publicclassConstruct (publicvoiddrinksType()/添加说明为了使用方便单独定义System.out.println(1.可乐(120 日元);System.out.println(2.橙汁(80 日元);System.out.println(3.绿茶(150 日元)” );publicvoidmoneyType说明为 System.out.println(1 : 10 日元);System.out.println(2 : 50 日元);System.out.println(3 : 100 日元);System.out
2、.println(4 : 500 日元);System.out.println(5 : 1000 日元);packageLevelSecond;importjava.util.Scanner;publicclassAutoSaleMachine publicstaticvoidmain(String args) tryConstruct cons =newConstruct();cons.drinksType();System.out.println(请选择饮品:);/ 添加()Scanner in =newScanner(System.in 殆 intId = in.nextInt();Pr
3、oduct p =newProduct();得出用户所选的饮品p.Pro(Id);catch(Exception e) System.out.println(输入无效);e.printStackTrace();/调用 Construct 对象/系统输入所选择的饮品号/调用 Product 中的 Pro 方 法控制用户选择饮品packageLevelSecond;publicclassProduct publicvoidPro(intId)Construct cons =newConstruct();Calculate cal =newCalculate();switch(Id)case1 :S
4、ystem.out.println(您选择的是可乐,请按一下规定现金付款。);/投入金额 的面值的提示cons.moneyType();/告知用户选用的饮品cal.Cal(120);/调用 Calculate 的计算方法 Calbreak;case2 :System.out.println(您选择的是橙汁,请按一下规定现金付款。);cons.moneyType();cal.Cal(80);break;case3 :System.out.println(您选择的是绿茶,请按一下规定现金付款。 );cons.moneyType();cal.Cal(80);break;default:System.
5、out.println(错误);break;packageLevelSecond;importjava.util.Scanner;publicclassCalculate intbackPay;/ 定义找零inttotalPay;/定义总金额publicvoidCal(intPrice)Scanner in =newScanner(System.in);System.out.println(请投币.”);/投入硬币totalPay= in.nextInt();BaseCalculate bc =newBaseCalculate();调用 BaseCalculatefi 勺计算方法oesE)s旧
6、部s裁s仔驱)c(DfeuuwCT5nso检S卜MW娴(Du一二)HuwszCT5dD_mAoJE(DsAsSUs-芝好W湘x(8_D_#eD_-2-2):;eD_AeJD_g_#-2+-2W枳布nb山ssCT5_n。布O(DS?-fes8出H_(躇娴)旧布芝nb诲山田。旧q)1A躇娴旧芝诲w田枳旧芝好Q隘o却l(/80_l_s-2s;e_工n。8。布0。祀出。|?/S|.B。)sCT5-no-CT5|1.(1)o(DsssT5o+u)二色8赧涕sz玄湛uto.EsssEoor)u(=+0+=wEmE亘sEsOPMUEmo.o.Ess(=+0+=sCRUol/lp8Eqnodr)(uw=E+m
7、01赧涕e躇娴BwYf芝湘Q三o-BlCLCL_M-2eCLUqMoeHcMpCLpMeoeqlKE00gswt?9swonogdMHegcEpupe一q1K1K(=+0+=intfiveHRemain = backPay-fiveHp*500;intoneHp = fiveHRemain/100;/求出找零中的 100 日元有几张 intoneHRemain = fiveHRemain-oneHp*100;intfiftyp = oneHRemain/50;/求出找零中的 50 日元有几张intfiftyRemain = oneHRemain-fiftyp*50;inttenp = fiftyRemain/10;/求出找零中的 10 日元有几张System.out.println(找零为:+backPay+分别为:);System.out.println(500 日元:+fiveHp+枚);System.out.println(100 日元:+oneHp+枚);System.out.println(50 日元:+fiftyp+枚);System.out.println(10 日元:+tenp+枚”);