-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab5.java
More file actions
132 lines (101 loc) · 3.62 KB
/
Copy pathLab5.java
File metadata and controls
132 lines (101 loc) · 3.62 KB
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
// 1. Develop a Java program to demonstrate Banking System, demonstrate different
// features such deposit, withdrawal of the amount can be done with ease. Demonstrate
// for atleast 15 customers.
// import java.util.Scanner;
class Bank {
String name;
String id;
int balance;
String[][] transactions = new String[10][2];
int transactionIndex = 0;
int deposit(int amt) {
balance += amt;
System.out.println("Amount " + amt + " deposited");
if (transactionIndex < 10) {
transactions[transactionIndex][0] = "+";
transactions[transactionIndex][1] = String.valueOf(amt);
transactionIndex++;
}
return balance;
}
int withdraw(int amt) {
if (amt > balance) {
System.out.println("Insufficient balance");
} else {
balance -= amt;
System.out.println("Amount " + amt + " withdrawn");
if (transactionIndex < 10) {
transactions[transactionIndex][0] = "-";
transactions[transactionIndex][1] = String.valueOf(amt);
transactionIndex++;
}
}
return balance;
}
void display() {
System.out.println("Name: " + this.name);
System.out.println("ID: " + this.id);
System.out.println("Balance: " + this.balance);
for (int i = 0; i < transactionIndex; i++) {
System.out.println("Transaction: " + transactions[i][0] + " " + transactions[i][1]);
}
}
void getDetails(Scanner input) {
System.out.println("Enter your name:");
this.name = input.nextLine();
System.out.println("Enter your bank ID:");
this.id = input.nextLine();
System.out.println("Enter your initial balance:");
this.balance = input.nextInt();
input.nextLine();
}
}
public class bankingsystem {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of customers you want to enter details for:");
int n = input.nextInt();
input.nextLine();
Bank[] customers = new Bank[n];
for (int i = 0; i < n; i++) {
Bank c1 = new Bank();
c1.getDetails(input);
customers[i] = c1;
}
while (true) {
System.out.println("\nSelect an option:");
System.out.println("1. Deposit");
System.out.println("2. Withdraw");
System.out.println("3. Display Account Details");
System.out.println("4. Exit");
int choice = input.nextInt();
input.nextLine();
if (choice == 4) {
break;
}
System.out.println("Enter customer index (0 to " + (n - 1) + "):");
int customerIndex = input.nextInt();
input.nextLine();
switch (choice) {
case 1:
System.out.println("Enter amount to deposit:");
int depositAmount = input.nextInt();
input.nextLine();
customers[customerIndex].deposit(depositAmount);
break;
case 2:
System.out.println("Enter amount to withdraw:");
int withdrawAmount = input.nextInt();
input.nextLine();
customers[customerIndex].withdraw(withdrawAmount);
break;
case 3:
customers[customerIndex].display();
break;
default:
System.out.println("Invalid option. Please try again.");
}
}
input.close();
}
}