// object-oriented version of the ATM machine // analyzed a total of two ATM objects and user objects // clear screen function let clear = () => process.stdout.write (process.platform === 'win32'? '\ X1Bc' : '\ X1B [2J \ X1B [3J \ X1B [H' ); // user constructor the let the user = function (the userName, totalMoney) { the this .userName = the userName; the this .totalMoney = totalMoney; } // the ATM machine constructor the let the ATM = function () {} // the ATM machine queries ATM.prototype.checkMoney = function (User) { the console.log ( "current card balance is:" , user.totalMoney); the console.log ( "Press ENTER to return" {); } // the ATM machine saving function ATM.prototype.saveMoney = function (Money, User) { user.totalMoney + = Money; the console.log ( "money has been deposited, the current balance on the card:" , User .totalMoney); the console.log ( "press ENTER to return" ); } // the ATM to withdraw money function ATM.prototype.outputMoney = function (Money, User) { IF (Money> user.totalMoney) { the console.log ( "insufficient balance on the card" ); the console.log ( "press ENTER to return" ); } the else user.totalMoney - = Money; the console.log ( "the money has been removed, the current balance on the card:" , user.totalMoney); the console.log ( "Press ENTER to return" ); } } // ---------- -------------------------------------------------- ----- the let main = function () { the let user = new new the user ( "old beams", 100,000); // instantiating a user object the let ATM = new new ATM (); // instantiate ATM machine the let = the doWork to true ; the while (the doWork) { Clear (); the console.log ( "Welcome,", user.username); the console.log ("Please select the function you want to perform: 1. query 2. 3. withdraw money saving 4. Quit" ); the let the Choose = parseInt (readline.question ( "" )); Switch (the Choose) { Case 1 : { the Clear (); atm.checkMoney (the User); readline.question ( "" ); BREAK ; } Case 2 : { the Clear (); console.log ( "Please enter the amount you want to deposit:" ); the let Money= parseInt (readline.question ( "" )); atm.saveMoney (Money, the User); readline.question ( "" ); BREAK ; } Case . 3 : { Clear (); the console.log ( "Enter the amount you want to take:" ); the let Money = the parseInt (readline.question ( "" )); ATM .outputMoney (Money, the User); readline.question ( "" ); BREAK ; } Case 4: { the Clear (); console.log ( "Thank you for your use, good-bye!" ); doWork = false ; readline.question ( "" ); the Clear (); BREAK ; } } } } the let readline = The require ( "readline-Sync " ); main ();