-
Notifications
You must be signed in to change notification settings - Fork 0
/
oop.ts
137 lines (116 loc) · 4.24 KB
/
oop.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import inquirer from "inquirer";
//BanK AccounT InterFace
interface bankAccount{
accountNumber: number;
balance:number;
withdraw(amount: number):void
deposit(amount: number):void
checkBalance():void
}
//BanK AccounT Class
class bankAccount implements bankAccount{
accountNumber: number;
balance: number;
constructor( accountNumber: number, balance: number){
this.accountNumber = accountNumber;
this.balance = balance;
}
//DeBiT MoneY
withdraw(amount: number): void{
if(this.balance >= amount){
this.balance -= amount;
console.log(`WithDrawaL OF $${amount} SuccesFull. RemaininG Balance: $${this.balance}`);
} else{
console.log("InsuFFicienT Balance...");
}
}
// CreDiT MoneY
deposit(amount: number):void {
if(amount > 100){
amount -= 1; //$1 Fee ChargeD IF More ThaN $100 IS DepoaiteD
} this.balance += amount;
console.log(`Deposit OF $${amount} SuccessFull.. RemaininG Balance: $${this.balance}`);
}
// ChecK Balance
checkBalance(): void {
console.log(`CurrenT Balance: $${this.balance}`);
}
}
// CusTomeR Class
class Customer{
firstName: string;
lastName: string;
gender: string;
age: number;
mobileNumber: number;
account: bankAccount;
constructor( firstName: string, lastName: string, gender: string, age: number, mobileNumber: number, account: bankAccount )
{
this.firstName = firstName
this.lastName = lastName
this.gender = gender
this.age = age
this.mobileNumber = mobileNumber
this. account = account
}
}
// CreaTe Bank AccounTs
const accounts: bankAccount[] = [
new bankAccount (1001, 500),
new bankAccount (1002, 1000),
new bankAccount (1003, 2000)
];
// CreaTe CustomeRs
const customers: Customer[] = [
new Customer ("Noor", "Shaikh", "Female", 15, 3162223334, accounts[0]),
new Customer ("Raza", "Shaikh", "Male", 18, 31442223334, accounts[1]),
new Customer (" Quddus", "Shaikh", "Male", 19, 31782223334, accounts[2])
]
// FuncTioN TO InteracT WitH BanK AccounT
async function service() {
do {
const accountNumberInput = await inquirer.prompt({
name: "accountNumber",
type: "number",
message: "Enter Your Account Number:"
})
const customer = customers.find(customer => customer.account.accountNumber === accountNumberInput.accountNumber)
if(customer){
console.log(`Welcome, ${customer.firstName} ${customer.lastName}!\n`);
const ans = await inquirer.prompt([{
name: "select",
type: "list",
message: "Select An OperaTion",
choices: ["Deposit", "Withdraw", "check Balance", "Exit"]
}]);
switch (ans.select) {
case "Deposit":
const depositAmount = await inquirer.prompt({
name: "amount",
type: "number",
message: "Enter The Amount To Deposit:"
})
customer.account.deposit(depositAmount.amount);
break;
case "Withdraw":
const WithdrawAmount = await inquirer.prompt({
name: "amount",
type: "number",
message: "Enter The Amount To Withdraw:"
})
customer.account.withdraw(WithdrawAmount.amount);
break;
case "check Balance":
customer.account.checkBalance();
break;
case "Exit":
console.log("ExiTinG BanK ProGram...")
console.log("\n ThankYou For Using Our BanK ServiceS.");
return;
}
}else{
console.log("InvaliD AccounT NumbeR. Please Try Again. ");
}
} while(true);
}
service();