Full Stack Web Development Courses with Real-time projects Start Now!!
Program 1
// ATM Application for Bank
"use strict"
const ps=require("prompt-sync")
const prompt=ps({sigint:true})
class Bank
{
constructor(acno,name,amount=0)
{
// console.log("This is create account method")
this.acno=acno
this.name=name
this.amount=amount
}
deposit(amount=0)
{
this.amount=this.amount+amount
}
withd(amount)
{
if(amount>this.amount)
console.log("Insufficient balance : Your current balance is : "+this.amount)
else
this.amount=this.amount-amount
}
displaybalance()
{
console.log("Account id: "+this.acno)
console.log("Account Hoder Name: "+this.name)
console.log("Balance: "+this.amount)
}
}
let choice
let B1=new Bank(101,'Vikas Sharma',6000)
let B2=new Bank(102,'Rajesh Gupta',2000)
let B3=new Bank(103,'Sheetal Verma',3000)
let B4=new Bank(104,'Sahil',5000)
let B5=new Bank(105,'Ashish',7000)
let B6=new Bank(106,'Dipesh',6000)
let B7=new Bank(107,'Nilesh',2000)
let B8=new Bank(108,'Megha',3000)
let B9=new Bank(109,'Pihu',5000)
let B10=new Bank(110,'Anmol',7000)
let myar=[]
myar.push(B1)
myar.push(B2)
myar.push(B3)
myar.push(B4)
myar.push(B5)
myar.push(B6)
myar.push(B7)
myar.push(B8)
myar.push(B9)
myar.push(B10)
do
{
console.log("--------------------Bank ATM-------------------------")
console.log(" 1.Deposit")
console.log(" 2.Withdrawal")
console.log(" 3.Balance Check")
console.log(" 4.Display All Details")
console.log(" 5.Exit")
console.log("---------------------------------------------------------")
choice=parseInt(prompt("Enter your choice"))
switch(choice)
{
case 1:
{
let f=0
let accountno=parseInt(prompt("Enter account number:"))
myar.some(element =>
{
if(element.acno==accountno)
{
f=1
console.log("Account Holder Name: "+ element.name)
let amt=parseInt(prompt("Enter amount for deposit: "))
element.deposit(amt)
return true
}
});
if(f==0)
console.log("Invalid account")
break;
}
case 2:
{
let f=0
let accountno=parseInt(prompt("Enter account number:"))
myar.some(element =>
{
if(element.acno==accountno)
{
f=1
console.log("Account Holder Name: "+ element.name)
let amt=parseInt(prompt("Enter amount for withdrawal: "))
element.withd(amt)
return true
}
});
if(f==0)
console.log("Invalid account")
break;
}
case 3:
{
let f=0
let accountno=parseInt(prompt("Enter account number:"))
myar.some(element =>
{
if(element.acno==accountno)
{
f=1
element.displaybalance()
return true
}
});
if(f==0)
console.log("Invalid account")
break;
}
case 4:
{
console.log("Account ID Name Balance")
myar.forEach(element =>
{
console.log(element.acno + " " + element.name + " " +element.amount)
});
break;
}
}
}while(choice!=5);