package computerworkthreechapter;
import java.util.*;
public class three_1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
money bank=new money();
Scanner reader=new Scanner(System.in);
System.out.print("欢迎使用Appilcation系统,请按任意(除0)键进入!");
int choice=reader.nextInt();
while(choice!=0){
System.out.println("请输入选项:");
System.out.println("1.存款");
System.out.println("2.取款");
System.out.println("3.显示余额");
int a=reader.nextInt();
switch(a){
case 1:
System.out.print("请输入存款金额:");
double currency=reader.nextDouble();
bank.putmoney(currency);
bank.getyu();
bank.put();
System.out.print("\n\n");
break;
case 2:
System.out.print("请输入取款金额:");
double get=reader.nextDouble();
bank.getmoney(get);
bank.getyu();
try{
if(bank.yu<0){
System.out.println("当前余额为:"+bank.money3);
System.out.println("余额不足,不能取款!");
choice=0;
throw new IllegalArgumentException("余额为负");
}
else{
System.out.print("取款成功!");
bank.getyu();
bank.put();
}
}
catch(IllegalArgumentException e)
{
System.out.print("出现的异常是:"+e.toString());
}
break;
case 3:
bank.getyu();
System.out.println("当前余额为:"+bank.yu);
System.out.print("\n\n");
break;
default:
System.out.println("输入有误,请重新输入:");
}
}
}
}
class money
{
public static double yu;
public static
double money1=0;
public
static double money2=0;
public
static double money3=0;
public double bank1;
Scanner reader=new Scanner(System.in);
public void putmoney(double money)
{
this.money1+=money;
}
public void getmoney(double money)
{
this.money2+=money;
}
public void getyu()
{
yu=money1-money2;
}
public void put()
{
money3=yu;
}
}