package ltb6w;
import java.util.*; public class Bank { private boolean bool=true;
private String select;
private String select2;
private double balance=0.0; //余额
private double inputbalance=0.0; private Scanner sc=new Scanner(System.in); public Bank() { System.out.println("请输入存款额度:"); } @SuppressWarnings("serial")
class NotSufficientFunds extends Exception { //自定义异常类 private String insufficient; NotSufficientFunds(String s ) { insufficient=s;
} public String getMessage() { return insufficient; } } public void deposite() throws Exception{//存款操作 try { inputbalance=sc.nextInt();// 容易出异常的地方 }catch (InputMismatchException e) { System.out.println("请输入数字:"); this.bool=false;
} if(inputbalance<0) { throw new NotSufficientFunds("存款不能是负数"); //抛出自定义异常
} this.balance=inputbalance+balance; System.out.println("存款总额:"+balance);
} public void withdrawa() throws Exception{//取款操作 System.out.println("请输入取款数:"); this.balance=balance-sc.nextInt(); if (balance<0) { //激发异常类 throw new NotSufficientFunds("余额已经是负数了"); } System.out.println("余额:"+this.getbalawal());
} public double getbalawal() { //获取余额操作 return balance;
} public void getBank() { System.out.println("是否继续存款:是or否"); select=sc.next(); // 容易出异常的地方 if("否".equals(select)) { while (true) { System.out.println("看仔细了!!!是否还继续取款:是or否"); try {
select2=sc.next(); // 容易出异常的地方 }catch (InputMismatchException e) { System.out.println("不要输入(是or否)之外无关的数据,从来,再来。"+e.getMessage()); } if("是".equals(select2)) { try {
withdrawa(); break;
} catch (Exception e) { e.printStackTrace();
} }else if ("否".equals(select2)){ System.out.println("不管你选不选否都当做退出。["+select2+"]"); break;
} } bool=false; System.out.println("已经成功退出"); }else if("是".equals(select)) {
System.out.println("继续输入金额,come on baby!");
}
} public static void main(String[] args) throws Exception { Bank b=new Bank(); while (b.bool) { b.deposite();
b.getBank(); } } }

最新文章

  1. 如何在移动设备上调试html5开发的网页
  2. Python实现冒泡排序
  3. lnmp 在nginx中配置相应的错误页面error_page
  4. Unity Built-in Shader详解二
  5. Deep Learning Workbench Installation Notes
  6. bzoj1937
  7. ANDROID_MARS学习笔记_S04_008_用Listview、自定义adapter显示返回的微博数据
  8. nosql newsql
  9. js的意义,引用方法及变量
  10. spring Annotation 笔记2.1
  11. Intel Core Microarchitecture Pipeline
  12. Opencv基础课必须掌握:滑动条做调色盘 -OpenCV步步精深
  13. Django--CRM
  14. HDU 5832 A water problem 水题
  15. More is better-多多益善
  16. 微信小程序 --- 页面跳转
  17. 数据链路层、ARP/RARP、ICMP、ping和traceroute
  18. python文件操作各种模式和常用方法总结r r+ rb r+b
  19. Maven:Non-resolvable parent POM: Failure to find错误
  20. nyoj 740 “炫舞家“ST

热门文章

  1. Xposed MultiDex Hook
  2. Python之路,第五篇:Python入门与基础5
  3. aliyun服务器对象存储oss
  4. openssl:AES CBC PKCS5 加解密 (C/GOLANG)
  5. vue查缺补漏题
  6. 简易计算器的java实现
  7. MyBatis #{} 取值注意事项
  8. HDU 1160:FatMouse's Speed(LIS+记录路径)
  9. 10 HashMap,Map.Entry,LinkedHashMap,TreeMap,Hashtable,Collections类
  10. hdu3613 Best Reward manacher+贪心+前缀和