-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankingApplication.java
More file actions
141 lines (111 loc) · 3.22 KB
/
Copy pathBankingApplication.java
File metadata and controls
141 lines (111 loc) · 3.22 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
133
134
135
136
137
138
139
140
141
package my;
import java.util.Scanner;
public class BankingApplication {
public static void main(String[] args) {
// TODO Auto-generated method stub
BankAccount obj1 =new BankAccount("Anumandla Bharath Srinivas","UBI0000121");
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 && amount <= balance)
{
balance = balance - amount;
previousTransaction = -amount;
}
else if (amount > balance)
{
System.out.println("Insufficient funds!");
}
}
void getpreviousTransaction()
{
if(previousTransaction > 0)
{
System.out.print("Deposit:"+previousTransaction);
}
else if(previousTransaction < 0)
{
System.out.println("Withdraw:"+Math.abs(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("CustomerID:"+customerID);
System.out.println("\n");
System.out.println("A.Check Balance");
System.out.println("B.Deposit");
System.out.println("C.Withdraw");
System.out.println("D.PreviousTransaction");
System.out.println("E.Exit");
do {
System.out.println("================================================================");
System.out.println("Enter an option");
System.out.println("================================================================");
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:");
int amount = scanner.nextInt();
deposit(amount);
System.out.println("\n");
break;
case 'C':
System.out.println("---------------------------");
System.out.println("Enter an amount to Withdraw:");
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;
case 'E':
System.out.println("*************************************");
break;
default:
System.out.println("Invalid Option !! Please enter again");
break;
}
}while(option!='E');
System.out.println("ThankYou for using our service");
scanner.close();
}
}