-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankDemo.java
More file actions
185 lines (185 loc) · 6.42 KB
/
BankDemo.java
File metadata and controls
185 lines (185 loc) · 6.42 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import java.util.*;
interface s
{
Scanner sc=new Scanner(System.in);
}
interface Account_Interface
{
public double deposit(double d_money);
public double withdraw(double w_money);
}
abstract class Account
{
int account_id,customer_id;
}
class SavingAccount extends Account implements Account_Interface
{
double balance;
SavingAccount()
{
account_id=-1;
customer_id=-1;
balance=0;
}
SavingAccount(int account_id,int customer_id,double balance)
{
this.account_id=account_id;
this.customer_id=customer_id;
this.balance=balance;
}
public double deposit(double d_money)
{
if(account_id==-1)
{
System.out.print("Account does not exist!!");
return -1;
}
else
{
balance=balance+d_money;
return balance;
}
}
public double withdraw(double w_money)
{
if(account_id==-1)
{
System.out.print("Account does not exist!!");
return -1;
}
else
{
if(w_money<=balance)
{
balance=balance-w_money;
return balance;
}
else
{
System.out.print("Sufficient amount not present in the account. Please deposit INR "+(w_money-balance)+" to withdraw INR "+w_money+"\n");
return -2;
}
}
}
void display()
{
System.out.println("Account ID: "+account_id);
System.out.println("Customer ID: "+customer_id);
System.out.println("Total amount available in your account: INR "+balance);
}
}
class BankDemo implements s
{
public static void main(String args[])
{
char wish='y';
int n,account_id,customer_id,ac_id,choice;
double d_money,w_money,balance;
System.out.print("Enter the number of Saving accounts to be stored: ");
n=sc.nextInt();
sc.nextLine();
SavingAccount objects[]=new SavingAccount[n];
System.out.println("Enter the Savings Account details:-");
for(int i=0;i<n;i++)
{
System.out.println("\nRecord "+(i+1));
System.out.print("Enter the Account ID: ");
account_id=sc.nextInt();
sc.nextLine();
System.out.print("Enter the Customer ID: ");
customer_id=sc.nextInt();
sc.nextLine();
System.out.print("Enter the initial balance of your account: ");
balance=sc.nextInt();
sc.nextLine();
objects[i]=new SavingAccount(account_id,customer_id,balance);
}
do
{
System.out.println("Choose any one from the following options:-");
System.out.println("1.Deposit\n2.Withdraw\n3.Display\n4.Exit");
choice=sc.nextInt();
sc.nextLine();
switch(choice)
{
case 1:
{
boolean flag=false;
System.out.print("Enter the account ID to deposit amount: ");
ac_id=sc.nextInt();
sc.nextLine();
for(int i=0;i<n;i++)
{
if(objects[i].account_id==ac_id)
{
flag=true;
System.out.print("Enter the amount to be deposited: ");
d_money=sc.nextDouble();
sc.nextLine();
objects[i].deposit(d_money);
System.out.println("The updated balance of your account is: INR "+objects[i].balance);
break;
}
}
if(flag==false)
System.out.println("Savings account with Account ID "+ac_id+" not found!!");
break;
}
case 2:
{
boolean flag=false;
double temp;
System.out.print("Enter the account ID to withdraw amount: ");
ac_id=sc.nextInt();
sc.nextLine();
for(int i=0;i<n;i++)
{
if(objects[i].account_id==ac_id)
{
flag=true;
System.out.print("Enter the amount to be withdrawn: ");
w_money=sc.nextDouble();
sc.nextLine();
temp=objects[i].withdraw(w_money);
if(temp!=-2)
System.out.println("\nThe updated balance of your account is: INR "+objects[i].balance);
break;
}
}
if(flag==false)
System.out.println("Savings account with Account ID "+ac_id+" not found!!");
break;
}
case 3:
{
boolean flag=false;
System.out.print("Enter the account ID to display account details: ");
ac_id=sc.nextInt();
sc.nextLine();
for(int i=0;i<n;i++)
{
if(objects[i].account_id==ac_id)
{
flag=true;
objects[i].display();
break;
}
}
if(flag==false)
System.out.println("Savings account with Account ID "+ac_id+" not found!!");
break;
}
case 4:
{
System.out.println("Thanks for using our program!!");
System.exit(0);
break;
}
default:
System.out.println("Enter the correct choice from the given options!!");
}
System.out.print("Do you want to continue? (Y/N): ");
choice=sc.next().charAt(0);
}while(wish=='y' || wish=='Y');
}
}