import java.util.*; class MyException1 extends Exception{ String xinxi; MyException1(int m){ xinxi="余额不足!"; } public String toString(){ return xinxi; } } class bank{ int amount;//账户 int yue=2000;//余额 public void cunkuan(int m){ yue=yue+m; System.out.println(yue); } public void qukuan(int m) throws MyException1 { if (m>yue){ MyException1 exception=new MyException1(m); throw exception; } yue=yue-m; } public int chaxun(){ return yue; } } public class Test1 { public static void main(String args[]){ Scanner input=new Scanner(System.in); System.out.println("请输入1(存款);2(取款);3(查询)"); System.out.println("请输入金额!"); int a=input.nextInt(); int c=input.nextInt(); bank b=new bank(); try { switch (a){ case 1: b.cunkuan(c); case 2: b.qukuan(c); case 3: b.chaxun(); } }catch(MyException1 e){ System.out.println(e.toString()); } } }
10-19
2753
07-11
3352
11-27
5295
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交