java 模拟银行的自动取款机ATM 使用过程中的界面和用户交互过程

模拟银行的自动取款机ATM 使用过程中的界面和用户交互过程

功能说明:

(1)模拟自动取款机(ATM)的流程,实现查询银行卡余额、取款、存款、退出系统等功能。

(2)取款金额受卡余额的限制。


import java.util.Scanner;



public class Bank  
{
public static void main(String[] args) 
{
Scanner input=new Scanner(System.in);
Thread thread = Thread.currentThread();
double balance = 0;
double b;
int operation;
init i = new init();
do
{
i.getOut();
operation = input.nextInt();
if (operation == 1)
{
i.deopsit();
balance = input.nextDouble();
i.setBalance(balance);
i.await1();
try
       {
thread.sleep(1500);//暂停1.5秒后程序继续执行

catch (InterruptedException ie){
}
System.out.println("[]:操作成功 ! ! !");

}
else if (operation == 2)
{
i.atm();
b = input.nextDouble();
if (b>i.getBalance())
{
i.await2();
try
       {
thread.sleep(1500);//暂停1.5秒后程序继续执行

catch (InterruptedException ie){
}
System.out.println("[]:该账户不可透支,本次操作中断!");

}
else
{
i.setBalance(balance-b);
try
       {
thread.sleep(1500);//暂停1.5秒后程序继续执行

catch (InterruptedException ie){
}
System.out.println("[]:操作成功 ! ! !");

}
}
else if (operation == 3)
{
try
       {
thread.sleep(1500);//暂停1.5秒后程序继续执行

catch (InterruptedException ie){
}
System.out.println("余额为:"+i.getBalance());

}

}


while (operation != 0);
System.out.println("感谢您使用本程序,祝您生活愉快!!!");


}


}
class init
{


private double balance; 
init()
{
balance = 0;

}


void setBalance(double newbalance)
{
balance = newbalance;
}


double getBalance()//余额
{
return balance;
}


void getOut()
{
System.out.println("                 银行卡操作界面");
System.out.println("                 ---------------");
System.out.println("                 [存款--------1]");
System.out.println("                 [取款--------2]");
System.out.println("                 [余额--------3]");
System.out.println("                 [退卡--------0]");
System.out.println("                 ---------------");
System.out.println("请输入:");
}


void deopsit()//存款
{
System.out.println("请输入存款数:");
}


void atm()//取款
{
System.out.println("请输入取款数:");
}


void await1()//验钞
{
System.out.println("正在验钞,请稍后。。。");
}


void await2()//操作
{
System.out.println("正在操作,请稍后。。。");
}
}
发布了39 篇原创文章 · 获赞 41 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/wei_zhen_dong/article/details/80424776