【Java开源代码栏目提醒】:网学会员鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“Bank.java”一文,供大家参考学习
import java.io.*;
public class Bank
{
public static float total,take[],input[];
public static int i,j;
public void deposit() throws IOException
{
System.out.println("请输入你要存多少钱:");
BufferedReader save = new BufferedReader(new InputStreamReader(System.in));
input[i]=Float.parseFloat(save.readLine());
System.out.println("你已成功存入"+input[i]+"元钱");
total=total+input[i];
}
public void take() throws IOException ,BankException
{
if(take[j]>total)
{
throw new BankException("余额不足,取不出这么多钱");
}
System.out.println("请输入你要取多少钱:");
BufferedReader tak = new BufferedReader(new InputStreamReader(System.in));
try
{
take[j]=Float.parseFloat(tak.readLine());
total=total-take[j];
}
catch(IOException e)
{
System.out.println("错误:"+e.getMessage());
return;
}
System.out.println("你已成功取出"+take[j]+"元钱");
j=j+1;
}
public void display() throws IOException
{
System.out.println("你账户上还有"+total+"元钱");
}
public static void main(String[] args) throws IOException
{
Bank bankuser=new Bank();
take=new float[50];
input=new float[50];
System.out.println("请输入y然后回车进入银行系统");
char option;
while ((char)System.in.read()=='y')
{
System.in.skip(2);
System.out.println("请用数字选择你要进行的操作");
System.out.println("1.存钱\t2.取钱\t3.显示存款数 ");
option= (char) System.in.read();
System.in.skip(2); //跳过回车键
switch (option)
{
case '1':
bankuser.deposit();
break;
case '2':
try
{
bankuser.take();
}
catch(BankException e)
{
e.printStackTrace();
}
break;
case '3':
bankuser.display();
break;
}
System.out.println("要继续则输入然后回车,要退出请输入n");
}
}
}
上一篇:
BallIF.java
下一篇:
小学英语作文:讨厌的蟑螂(双语)