该自动取款机实现 查询,存入,取出,打印账单功能
并且实现良好的交互,模拟系统进行,用时间来延时处理
import java.util.Scanner;
public class ATM {
public static void Welcome() throws InterruptedException
{
System.out.println("===========================================================");
System.out.println("= 欢迎来到中国建设银行ATM自动存/取款 001号机 = ");
System.out.println("= = ");
System.out.println("= 如需办理业务输入您的卡号 = ");
System.out.println("= = ");
System.out.println("= ①输入卡号 = ");
System.out.println("= = ");
System.out.println("= ②忘记卡号?可输入与卡绑定的手机号通过短信查询 = ");
System.out.println("= = ");
System.out.println("= ③忘记密码 = ");
System.out.println("= = ");
System.out.println("= = ");
System.out.println("= 建设银行实时提醒您,在输入密码的时候用手遮挡好,如遇特殊 = ");
System.out.println("= 情况请立即报警! = ");
System.out.println("===========================================================");
Interface_Choice();
}
public static void Interface_Choice() throws InterruptedException//界面选择
{
Scanner input=new Scanner(System.in);
int i;//供用户选择服务
for(int j=0;j<15;j++)//用来暴力“清除”界面
System.out.println();
System.out.print("请选择服务:");
i=input.nextInt();
String Tel_Number;
switch (i) {
case 1:{
insert_ID();
break;
}
case 2:{
System.out.print("请输入您的手机号:");
Tel_Number=input.next();
if(Tel_Number.equals("18834388888"))
System.out.println("您的卡号为: 621700032000");
else
System.out.println("对不起,查无此号");
for(int j=0;j<3;j++)
System.out.println();
System.out.println(" 正在返回主界面·······");
Thread.sleep(1000);
for(int j=0;j<20;j++)//用来暴力“清除”界面
System.out.println();
Welcome();
}
case 3:{
System.out.println("请您于工作日带上相关证件去前台办理业务");
Thread.sleep(1000);
}
default:
Welcome();
}
}
public static void insert_ID() throws InterruptedException{
System.out.print("请输入12位卡号");
String ID;//卡号比密码长用string储存比long更节省空间,
int passwd,i = 0;//密码一般为六位
Scanner input=new Scanner(System.in);
ID=input.next();
System.out.print("\n");
if(ID.equals("621700032000")) {
for(i=0;i<3;i++) {
if(i==0)
System.out.print("请输入密码:\n");
passwd=input.nextInt();
if(passwd!=123456) {
if(i==2) {
System.out.println("抱歉,您今日输入错误已达到上限,请明日再试");
break;
}
System.out.print("密码错误,请重新输入:\n");
}
else
{
for(int j=0;j<3;j++)
System.out.println();
System.out.println(" 正在登陆请稍候······");
Thread.sleep(1000);
for(int j=0;j<17;j++)
System.out.println();
//准备调用输入正确密码后的界面函数
After_insert_ID_card();
}
}
}
else {
System.out.println("您的帐号输入有误,请仔细核对\n");
System.out.println("请选择下一步");
System.out.println("1 退出");
System.out.println("2 重新输入");
int j;
j=input.nextInt();
switch (j) {
case 1:
Welcome() ;
case 2:
insert_ID();
default:
Welcome() ;
}
}
}
public static void After_insert_ID_card() throws InterruptedException
{
System.out.println("===========================================================");
System.out.println("= 欢迎来到中国建设银行ATM自动存/取款 001号机 =");
System.out.println("= =");
System.out.println("= 请选择您需要办理的业务 =");
System.out.println("= =");
System.out.println("= ①实时存款 ②实时取款 =");
System.out.println("= =");
System.out.println("= ③实时查询 ④退卡 =");
System.out.println("= =");
System.out.println("= ⑤打印帐单 =");
System.out.println("= 建设银行实时提醒您,在输入密码的时候用手遮挡好,如遇特殊 =");
System.out.println("= 情况请立即报警! =");
System.out.println("===========================================================");
Users_Choice();
}
static int k=0;//全局变量 用来记录money随着用户存取的变化而记录
static double money;
static double mon []=new double [100];
public static void Users_Choice( ) throws InterruptedException//用户选择
{
Scanner input=new Scanner(System.in);
if(k==0)
{
mon[k]=500;
int i,jj;//供用户选择服务
for(int j=0;j<15;j++)//用来暴力“清除”界面
System.out.println();
System.out.print("请选择服务:");
i=input.nextInt();
money=mon[k];//原来帐户有500块
int deposit,withdrawal;//存款,取款
switch (i) {
case 1:{
System.out.print("请将钞票叠整齐放入存钞口,不多于100张:\n");
deposit=input.nextInt();
if(deposit>10000) {
System.out.println("抱歉,请取出多余部分,并重新放入");
Thread.sleep(1000);
}
System.out.print("您本次存入"+deposit+"元");
money+=deposit;
mon[++k]=money;//y用数组保存money每一步更新的值
System.out.print("如果继续交易请按 1 或按任意键选择返回界面选择退卡\n");
jj=input.nextInt();
if(jj==1) {
System.out.print("请将钞票叠整齐放入存钞口,不多于100张:\n");
deposit=input.nextInt();
System.out.print("您本次存入"+deposit+"元");
money+=deposit;
mon[++k]=money;
System.out.print("如果继续交易请按 1 或按任意键选择返回界面选择退卡\\n");
jj=input.nextInt();
}
else
break;
}
case 2:{
System.out.print("请输入取款金额不多于10000:\n");
withdrawal=input.nextInt();
if(withdrawal>money) {
System.out.println("抱歉,您的余额不足\n");
Thread.sleep(1000);
After_insert_ID_card();
}
else if(withdrawal>10000)
{
System.out.println("抱歉,请您重新输入\n");
Thread.sleep(1000);
After_insert_ID_card();
}
else
{
System.out.print("您本次取出"+withdrawal+"元");
money-=withdrawal;
mon[++k]=money;
System.out.print("如果继续交易请按 1 或按任意键选择返回界面选择退卡\n");
jj=input.nextInt();
if(jj==1) {
System.out.print("请输入取款金额不多于10000:\n");
withdrawal=input.nextInt();
if(withdrawal>money) {
System.out.println("抱歉,您的余额不足\n");
Thread.sleep(1000);
After_insert_ID_card();
}
System.out.print("您本次取出"+withdrawal+"元");
money-=withdrawal;
mon[++k]=money;
System.out.print("如果继续交易请按 1 或按任意键选择返回界面选择退卡\n");
jj=input.nextInt();
}
else
After_insert_ID_card();
}
}
case 3:{
System.out.print("您卡内的余额为"+mon[k]+"元");
for(int m=0;m<5;m++)
System.out.println();
System.out.print(" 即将返回界面······");
Thread.sleep(1000);
for(int m=0;m<5;m++)
System.out.println();
After_insert_ID_card();
}
case 4:{
System.out.print(" 谢谢您本次使用建设银行!");
for(int m=0;m<5;m++)
System.out.println();
System.out.print(" 即将返回界面······");
Thread.sleep(1000);
Welcome();
}
case 5:{
int loop;
for(loop=0;loop<k;loop++)
{
if(mon[loop]<mon[loop+1])
{
System.out.println("存入"+(mon[loop+1]-mon[loop])+"元");
}
else
{
System.out.println("取出"+(mon[loop]-mon[loop+1])+"元");
}
}
}
default:
Users_Choice();
}
}
else
{
int i,jj;//供用户选择服务
for(int j=0;j<15;j++)//用来暴力“清除”界面
System.out.println();
System.out.print("请选择服务:");
i=input.nextInt();
money=mon[k];//如果不是第一次输入的话,money为上一次变更的值
int deposit,withdrawal;//存款,取款
switch (i) {
case 1:{
System.out.print("请将钞票叠整齐放入存钞口,不多于100张:\n");
deposit=input.nextInt();
if(deposit>10000) {
System.out.println("抱歉,请取出多余部分,并重新放入");
Thread.sleep(1000);
}
System.out.print("您本次存入"+deposit+"元");
money+=deposit;
mon[++k]=money;
System.out.print("如果继续交易请按 1 或按任意键选择返回界面选择退卡\n");
jj=input.nextInt();
if(jj==1) {
System.out.print("请将钞票叠整齐放入存钞口,不多于100张:\n");
deposit=input.nextInt();
System.out.print("您本次存入"+deposit+"元");
money+=deposit;
mon[++k]=money;
System.out.print("请选择继续交易或退卡\n");
jj=input.nextInt();
}
else
After_insert_ID_card();
}
case 2:{
System.out.print("请输入取款金额不多于10000:\n");
withdrawal=input.nextInt();
if(withdrawal>money) {
System.out.println("抱歉,您的余额不足\n");
Thread.sleep(1000);
After_insert_ID_card();
}
else if(withdrawal>10000)
{
System.out.println("抱歉,请您重新输入\n");
Thread.sleep(1000);
After_insert_ID_card();
}
else
{
System.out.print("您本次取出"+withdrawal+"元");
money-=withdrawal;
mon[++k]=money;
System.out.print("如果继续交易请按 1 或按任意键选择返回界面选择退卡\n");
jj=input.nextInt();
if(jj==1) {
System.out.print("请输入取款金额不多于10000:\n");
withdrawal=input.nextInt();
if(withdrawal>money) {
System.out.println("抱歉,您的余额不足\n");
Thread.sleep(1000);
After_insert_ID_card();
}
System.out.print("您本次取出"+withdrawal+"元");
money-=withdrawal;
mon[++k]=money;
System.out.print("如果继续交易请按 1 或按任意键选择返回界面选择退卡\n");
jj=input.nextInt();
}
else
After_insert_ID_card();
}
}
case 3:{
System.out.print("您卡内的余额为"+mon[k]+"元");
for(int m=0;m<5;m++)
System.out.println();
System.out.print(" 即将返回界面······");
Thread.sleep(1000);
for(int m=0;m<5;m++)
System.out.println();
After_insert_ID_card();
}
case 4:{
System.out.print(" 谢谢您本次使用建设银行!");
for(int m=0;m<5;m++)
System.out.println();
System.out.print(" 即将返回界面······");
Thread.sleep(1000);
Welcome();
}
case 5:{
for(i=0;i<10;i++)
System.out.println();
System.out.print(" 正在查询请稍候······\n");
Thread.sleep(1000);
for(i=0;i<10;i++)
System.out.println();
System.out.print("您的近期帐单如下\n");
int loop;
for(loop=0;loop<k;loop++)
{
if(mon[loop]<mon[loop+1])
{
System.out.println("第"+(loop+1)+"次存入"+(mon[loop+1]-mon[loop])+"元");
}
else
{
System.out.println("第"+(loop+1)+"次取出"+(mon[loop]-mon[loop+1])+"元");
}
}
}
default:
Users_Choice();
}
}
}
public static void main(String[] args) throws InterruptedException {
Welcome();
}
}