日期:2014-05-20 浏览次数:20813 次
package cn.puruidong.accp_13; /** * @author PuRuidong * */ /* * 包含错误! */ import java.util.Scanner; public class Account { private int num ; //录入菜单数字 private double money ; //存款金额 private double offmoney ; //取款 private double sum ; public int show (int num , double money ,double offmoney,double sum){ num = 0 ; //菜单选择 offmoney = 0.0 ; //取款 money = 0.0 ; //存款的初始值 sum = 0.0 ; Scanner input = new Scanner (System.in); boolean zhi = true ; //定义Boolean变量,确定循环 System.out.println("1:存款\t2.取款\t0.退出"); System.out.println("请选择你需要办理的业务:"); do { num = input.nextInt();//录入菜单数字 switch (num){ case 1 : System.out.println("请输入存款金额:"); money = input.nextDouble();//录入存款 if (money >0){ //存款必须大于0 System.out.println("存款成功"); zhi = true ;//值为真,继续运行 sum = money+sum ; //存款累加 //money = 0.0 ; } else { System.out.println("存款输入错误,请重新输入!"); zhi = true ; break; } System.out.println(); break; case 2 :{ System.out.println("请输入你的取款金额:"); offmoney = input.nextDouble (); if (offmoney>money){ System.out.println("取款成功"); System.out.println("***当前余额是:"+(money-offmoney)+"***"); zhi = true ; }else { System.out.println("抱歉,余额不足!"); zhi = false ; } } break; case 0 : System.out.println("谢谢使用!"); zhi = false ;//值为假退出循环 break; } System.out.println("***当前余额为:"+sum+"元***"); System.out.println("1:存款\t2.取款\t0.退出"); System.out.println("请选择你需要办理的业务:"); num = input.nextInt();//录入菜单数字 continue ; } while (zhi==false); return num ; } public static void main(String[] args) { Account center = new Account (); int num = 0; double money = 0.0; double offmoney = 0.0; double sum = 0.0 ; center.show(num, money, offmoney, sum); } }
package cn.puruidong.accp_13; import java.util.Scanner; public class TestAccount { private int caidan ; private double money ; private double offmoney ; private double sum ; private boolean zhi ; public TestAccount (){ super(); } public int show (){ Scanner input = new Scanner (System.in); System.out.println("1.存款\t2.取款\t3.退出"); System.out.println("请选择你需要的办理的业务:"); caidan = input.nextInt(); return caidan; } public double cunkuan (double sum){ Scanner input = new Scanner (System.in); do { caidan = input.nextInt(); if (caidan==1){ System.out.println("请输入存款金额:"); money = input.nextDouble(); System.out.println("存款成功"); sum = money + sum ; } System.out.println("***当前余额是"+sum+"******"); System.out.println("1.存款\t2.取款\t3.退出"); System.out.println("请选择你需要的办理的业务:"); } while (caidan==0); return sum ; } public double qukuan (double offmoney){ Scanner input = new Scanner (System.in); for (int i =1;i<100;i++){ if (caidan==2){ System.out.println("请输入取款金额"); offmoney = input.nextDouble(); if (sum>offmoney&&zhi==true){ System.out.println("取款成功!"); }else { System.out.println("余额不足!"); } } } if (zhi==true){ System.out.println("***当前余额是:"+(sum-offmoney)+"*****"); } return offmoney ; } public void tuichu (){ if (caidan==3){ System.out.println("谢谢使用!"); } zhi = false ; } public static void main(String[] args) { TestAccount center = new TestAccount (); double sum =0.0 ; double offmoney = 0.0 ; boolean zhi = true ; do{ center.show(); center.cunkuan(sum); center.qukuan(offmoney); center.tuichu(); }while (zhi==false); } }