码迷,mamicode.com
首页 > 编程语言 > 详细

简易柜员机 JAVAscript

时间:2018-05-21 01:07:31      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:bsp   hang   ++   put   adl   console   class   pre   使用   

const readline = require(‘readline-sync‘);
let arr = [[‘zhangsan‘,‘123456‘],[‘lisi‘,‘123456‘]];
let menu=‘1.取款\n2.存款\n3.查看\n4.退出‘;

let isGister=false;    //定义初始登录错误
let inputfalse=0;      //定义输入错误次数

while(!isGister)
{
    console.log(‘请输入帐号:‘)
    let username = readline.question();
    console.log(‘请输入密码:‘)
    let password = readline.question();
for ( i = 0; i < arr.length; i++) 
{
    if (username==arr[i][0]&&password==arr[i][1])
     {
        console.log(‘登录成功‘);
        let flag=true;
        let balance=0;
        while(flag)
       {
            console.log(menu);
            console.log(‘请选择:‘)
            let item = readline.question()-0;
            switch (item) {
                case 1:
                {   let flag1=true;
                     while(flag1)
                    {
                        console.log(`当前余额为${balance}元,请输入取款金额:`)
                        let outmoney = readline.question();
                        balance-=outmoney;
                        console.log(`取款成功,当前余额为${balance}元。`)
                        console.log(‘继续取款请按1,返回上一级就按0‘)
                        let item2 = readline.question()-0;
                        switch (item2) {
                            case 1:  break;
                                
                            case 0:  flag1=false;
                            
                          
                        }
                    }   
                    break;1

                }
                case 2:
                {   let flag1=true;
                     while(flag1)
                    {
                        console.log(`当前余额为${balance}元,请输入存入金额:`)
                        let savemoney = readline.question()-0;
                        balance+=savemoney;
                        console.log(`取款成功,当前余额为${balance}元。`)
                        console.log(‘继续存款请按1,返回上一级就按0‘)
                        let item2 = readline.question()-0;
                        switch (item2) {
                            case 1:  break;
                                
                            case 0:  flag1=false;

                            
                        }
                    }   
                    break;
                } 
                case 3:
                {   
                        console.log(`当前余额为${balance}元,请输入取款金额:`)
                        console.log(‘返回上一级请按0‘)
                        let item2 = readline.question()-0;
                        switch (item2) {
                            case 1:  break;
                                
                            case 0:  flag1=false;
                        }
                       
                    break;
                }           
                case 4:
                {
                   console.log(‘感谢使用!‘)
                    flag=false;
                    break;
                }
                default:console.log(‘输入有误,请重新输入:‘)
            }
        }   
       isGister=true;
        }
}
     if(!isGister)
     {
         
         console.log(‘登录失败,请重新登录‘);
         inputfalse++;
         }
   
     if(inputfalse==3)
     {
         console.log(‘输入次数过多,锁卡‘)
         break;
     }
}

 

简易柜员机 JAVAscript

标签:bsp   hang   ++   put   adl   console   class   pre   使用   

原文地址:https://www.cnblogs.com/web--yang/p/9065210.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!