-
Notifications
You must be signed in to change notification settings - Fork 39
/
Basic Banking Application
126 lines (92 loc) · 3.16 KB
/
Basic Banking Application
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
import java.util.Scanner;
public class BankingAppication {
public static void main(String[] args) {
BankAccount obj1 = new BankAccount("Shruti","880011");
obj1.showMenu();
}
}
class BankAccount{
int balance;
int previousTransaction;
String customerName;
String customerId;
BankAccount(String cname, String cid){
customerName = cname;
customerId = cid;
}
void deposit(int amount) {
if(amount != 0) {
balance = balance + amount;
previousTransaction = amount;
}
}
void withdraw(int amount) {
if(amount != 0) {
balance = balance - amount;
previousTransaction = -amount;
}
}
void getPreviousTransaction() {
if(previousTransaction > 0) {
System.out.println("Deposited: " + previousTransaction);
} else if(previousTransaction < 0) {
System.out.println("Withdrawn: "+ previousTransaction);
} else {
System.out.println("No transaction occured");
}
}
void showMenu() {
char option = '\0';
Scanner scanner = new Scanner(System.in);
System.out.println("Welcome: " + customerName);
System.out.println("Your ID is: " + customerId);
System.out.println("/n");
System.out.println("A. ChechBalance");
System.out.println("B. Deposit");
System.out.println("C. Withdraw");
System.out.println("D. Previous Transaction");
System.out.println("E. Exit");
}
do{
System.out.println("*****************************************************************************************************************************");
System.out.println("Enter an option");
System.out.println("*****************************************************************************************************************************");
Scanner scanner;
char option = scanner.next().charAt(0);
System.out.println("\n");
switch(option) {
case 'A':
System.out.println("------------------------------------------------------------");
System.out.println("Balance = "+balance);
System.out.println("------------------------------------------------------------");
System.out.println("\n");
break;
case 'B':
System.out.println("------------------------------------------------------------");
System.out.println("Enter an amount to deposit : ");
System.out.println("------------------------------------------------------------");
int amount = scanner.nextInt();
deposit(amount);
System.out.println("\n");
break;
case 'C':
System.out.println("------------------------------------------------------------");
System.out.println("Enter an amount to deposit : ");
System.out.println("------------------------------------------------------------");
int amount2 = scanner.nextInt();
withdraw(amount2);
System.out.println("\n");
break;
case 'D':
System.out.println("------------------------------------------------------------");
getPreviousTransaction();
System.out.println("------------------------------------------------------------");
System.out.println("\n");
break;
default:
System.out.println("Invalid Option!! Please enter again");
break;
} while(option != 'E');
System.out.println("ThankYou for using our services");
}
}