-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram-9.js
48 lines (38 loc) · 1.25 KB
/
program-9.js
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
// Write a JavaScript program that creates a class called Bank with properties for bank names and branches. Include methods to add a branch, remove a branch, and display all branches. Create an instance of the Bank class and perform operations to add and remove branches.
class Bank {
constructor() {
this.bankName = "";
this.branches = [];
}
setBankName(name) {
this.bankName = name;
}
addBranch(branchName) {
this.branches.push(branchName);
}
removeBranch(branchName) {
const index = this.branches.indexOf(branchName);
if (index !== -1) {
this.branches.splice(index, 1);
}
}
displayBranches() {
console.log(`Branches of ${this.bankName}:`);
for (const branch of this.branches) {
console.log(branch);
}
}
}
// Create an instance of the Bank class
const bankInstance = new Bank();
bankInstance.setBankName("MyBank");
// Perform addition operations
bankInstance.addBranch("Main Branch");
bankInstance.addBranch("Downtown Branch");
bankInstance.addBranch("Suburb Branch");
console.log("After adding branches:");
bankInstance.displayBranches();
// Perform deletion operations
bankInstance.removeBranch("Downtown Branch");
console.log("\nAfter removing a branch:");
bankInstance.displayBranches();