概述
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("nn");
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("nn");
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;
}
}
最后
以上就是机灵向日葵为你收集整理的java 银行存款程序设计,设计一个模拟银行存款和取款的程序的全部内容,希望文章能够帮你解决java 银行存款程序设计,设计一个模拟银行存款和取款的程序所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复