用Java编写银行存钱取钱
const readline = require('readline-sync')//引用readline-sync
let s = 2;//错误的次数
for (let i = 0; i < 3; i++) {
console.log('请输入名:(由英文组成)');
let user = readline.question();
console.log('请输入密码:(由数字组成)');
let password = readline.question();
let arr = ['yang', '123456'];
if (user == arr[0] && password == arr[1]) {
console.log('欢迎您,登陆成功');
for (let yewu = 1; yewu >= 1; yewu++) {
console.log('请选择业务:\n1.存款: \n2.取款: \n3.查看: \n4.退出:');
let yewu = readline.question() - 0;
let money = 3000;
if (yewu > 4) {
console.log('对不起你输入的有误,请重新输入:')
continue;
}
switch (yewu) {
case 1:
//存款money2为钱变化后的总数
console.log('存款');
console.log('请输入存款金额:');
let cunkuan = readline.question() - 0;
money2 = money + cunkuan;
console.log('系统正在为你存钱请稍等。。。。。\n存钱成功您当前余额为' + money2);
continue;
case 2:
console.log('取款');
console.log('请输入取款金额:');
let qukuan = readline.question() - 0;
if (qukuan > money2) {
console.log('对不起你的余额不足!,您的余额不足,请重新输入或者退出');
} else {
money2 = money2 - qukuan;
console.log('当前余额为:' + money2);
}
continue;
case 3:
console.log('查看');
console.log('当前你的余额为:' + money2);
continue;
case 4:
console.log('退出');
console.log('欢迎你下次使用!');
break;
}break;
}
break;
} else {//输入不正确时
if (s != 0) {
console.log('密码或账户名错误,您还有' + s + "次机会,请重新输入:");
s--;
continue;
} else {
console.log('对不起,账户已锁定!');
break;
}
}
}