Home > front end >  ATM code as follows
ATM code as follows

Time:05-06

Const rs=the require (" readline - sync ");
//to create multiple accounts
Let the users=[
"Zh1", "111", 10000,
"Zh2", "222", 30000,
"Zh3", "333", 50000,
];

//system
The function xitong () {
The console. The log (registered login ` 1-2-0 - exit `);
Let num=rs. Question () - 0;
The switch (num) {
Case 1://login
Let dl=the main ();
break;
Case 2://register
The login ();
break;
Case 0://exit
The console. The log (` look forward to your next to the bank! Good bye! `);
return;
Default:
return;
}
}
Xitong ();

//register function body
The function the login () {
While (true) {//registration system Settings cycle
The console. The log (` please enter your registered account: `);
Let newZhangHu=rs. Question ();//access to create accounts
If (users. IndexOf (newZhangHu)==1) {//to find whether there is the account in the database
The console. The log (` please enter you created the account password: `);
Let newMiMa=rs. Question ();//access to create an account password
Users. Push (newZhangHu newMiMa, 80000);//add a new account password in the database and its balance
The console. The log (` congratulations handsome! Create account successfully! `);
main();//registered after the success of direct access to login
break;
} else {//if the account in the database is the output of the following
The console. The log (` account you entered already exists!!! `);
The console. The log (` please select you want to continue the operation of the
1 - continue to registered 2 - exit `);
Let the option=rs. Question () - 0;//get the user choose
If (option==2) {//choose 2 out directly, or continue to register (i.e., itself will again loop)
return;
}
}
}
}

Login//main program function body
The function main () {
Let arr=islogin ();//current login account subscript
If (arr [0]) {//whether the login success
Let the index=arr [1];
The console. The log (` respect of ${users [index]} welcome to good bank!!! `);
///to determine whether a user select "0"
Let the state=false;
while (! State) {
The console. The log (` please select function: 1, query 2, 3, saving take money 4, 5, transfer switch account 6, change the password 0, exit `);
Let the option=rs. Question () - 0;
The switch (option) {
Case 1:
The console. The log (` your current balance is: ${users [index + 2]} `);
break;
Case 2:
SaveMoney (index);
break;
Case 3:
DropMoney (index);
break;
Case 4:
TransMoney (index);
break;
Case 5:
Let QieHuanXiaBiao=QieHuanZhangHu (index);
If (QieHuanXiaBiao | | QieHuanXiaBiao===0) {
The index=QieHuanXiaBiao;
Switch the console. The log (` success! You have been in the ${users [index]} account `);
} else {
The console. The log (` switch failure!!!!!! `);
}
break;
Case 6:
Let ischange=XiuGaiMiMa (index);
The console. The log (` password is changed! Please login again. `);
If (ischange) {//change the password after the success, log back in
Let temp=islogin ();
If (temp [0]) {
The index=\ [1].
} else {
return;
}
}
break;
Case 0:
The console. The log (` welcome! Please take care! `);
The state=true;
return true;
}
}
}
}

//judgment function body
The function islogin (ischange=true, QieHuanXiaBiao=0) {
//set the login successful variable
Let the login=false;
//login successful account subscript
Let the index=0;
//login number is 3 times
Let count=3;
While (count) {//whether 3 chances out
Let inputName=users [QieHuanXiaBiao];
If (ischange) {
The console. The log (" please input your account: ");//input account
InputName=rs. Question ();
}
For (the let I=0; I & lt; Users. Length; I++) {
If (inputName==users [I]) {//account if there is a
The console. The log (" please enter your password: ");//input password
Let inputPWD=rs. Question ();
If (inputPWD==users [I + 1]) {//whether the password right
The login=true;//login success
The index=I;//modify account subscript
//count=3;//the number of restore default login
The return/login, the index;
} else if (count==1) {
The console. The log (` password input error, you has finished with opportunities for 3 times, account freeze. `);
count=0;
break;
} else {
The console. The log (` password input error, please input again, you still have ${- count} second chance! `);
break;
}
} else if (I==users. The length - 1 & amp; & The count & gt; 1) {//the last value compared to the array, and the opportunity to have
The console. The log (` account input errors, please input again, you still have ${- count} second chance! `);
Ischange=true;
} else if (I==users. The length - 1 & amp; & Count==1) {
Console. The log (` account input errors, your 3 times opportunity has been exhausted, account freeze. `);
count=0;//the current count value is 1, to assign a value of 0, terminate the login function,
break;

}
}
}
Return (false);
}

//save function body
The function saveMoney (index) {
The console. The log (` please enter the amount you want to deposit: `);
Let saveMoney=rs. Question () - 0;
if (! IsNaN (saveMoney)) {//whether the input for the numeric
The users [index + 2] +=saveMoney//balance change
The console. The log (` deposit success! `);
} else {
The console. The log (` you input is wrong!!! `);//input amount is not for numeric reminding customers
}
}

//draw money function body
The function dropMoney (index) {
The console. The log (` please enter the amount you want to remove `);
Let dropMoney=rs. Question () - 0;
if (! The isNaN (dropMoney)) {
If (dropMoney & lt;=the users [index + 2]) {//whether the balance is enough
Users - [index + 2]=dropMoney;
The console. The log (draw money ` success!!! `);
} else {
The console. The log (` your balance is insufficient! Withdrawals failed! `);//to insufficient remind user
}
} else {
The console. The log (` you input is wrong!!! `);
}
}

//transfer function body
The function transMoney (index) {
The console. The log (` please input you want to turn to account: `);
Let ZhuanRuZhangHu=rs. Question ();
If (ZhuanRuZhangHu!=the users [index]) {//judgment transfer account is not the current account
Let transIndex=users. IndexOf (ZhuanRuZhangHu);//return transfer accounts subscript
If ((transIndex!=1) & amp; & (transIndex % 3==0)) {//judge whether there is a transfer account
The console. The log (` please enter transfer amount: `);
Let transMoney=rs. Question () - 0;
if (! The isNaN (transMoney)) {
If (transMoney & lt;=the users [index + 2]) {
//current account to reduce money
Users - [index + 2]=transMoney;
//transfer accounts to add money
The users [transIndex + 2] +=transMoney;
The console. The log (` transfer success!!!!!! `);
} else {
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related