1+ //TASK 3 OIBSIP
2+ import java .util .Scanner ;
3+
4+ class BankAccount {
5+
6+ String name ;
7+ String userName ;
8+ String password ;
9+ String accountNo ;
10+ float balance = 10000f ;
11+ int transactions = 0 ;
12+ String transactionHistory = "" ;
13+
14+ // BankAccount(String name, String userName, String password, String accountNo) {
15+ // this.name = name;
16+ // this.userName = userName;
17+ // this.password = password;
18+ // this.accountNo = accountNo;
19+ // }
20+
21+ public void register () {
22+ Scanner sc = new Scanner (System .in );
23+ System .out .print ("\n Enter Your Name - " );
24+ this .name = sc .nextLine ();
25+ System .out .print ("\n Enter Your Username - " );
26+ this .userName = sc .nextLine ();
27+ System .out .print ("\n Enter Your Password - " );
28+ this .password = sc .nextLine ();
29+ System .out .print ("\n Enter Your Account Number - " );
30+ this .accountNo = sc .nextLine ();
31+ System .out .println ("\n Registration completed..kindly login" );
32+ }
33+
34+ public boolean login () {
35+ boolean isLogin = false ;
36+ Scanner sc = new Scanner (System .in );
37+ while ( !isLogin ) {
38+ System .out .print ("\n Enter Your Username - " );
39+ String Username = sc .nextLine ();
40+ if ( Username .equals (userName ) ) {
41+ while ( !isLogin ) {
42+ System .out .print ("\n Enter Your Password - " );
43+ String Password = sc .nextLine ();
44+ if ( Password .equals (password ) ) {
45+ System .out .print ("\n Login successful!!" );
46+ isLogin = true ;
47+ }
48+ else {
49+ System .out .println ("\n Incorrect Password" );
50+ }
51+ }
52+ }
53+ else {
54+ System .out .println ("\n Username not found" );
55+ }
56+ }
57+ return isLogin ;
58+ }
59+
60+ public void withdraw () {
61+
62+ System .out .print ("\n Enter amount to withdraw - " );
63+ Scanner sc = new Scanner (System .in );
64+ float amount = sc .nextFloat ();
65+ try {
66+
67+ if ( balance >= amount ) {
68+ transactions ++;
69+ balance -= amount ;
70+ System .out .println ("\n Withdraw Successfully" );
71+ String str = amount + " Rs Withdrawed\n " ;
72+ transactionHistory = transactionHistory .concat (str );
73+
74+ }
75+ else {
76+ System .out .println ("\n Insufficient Balance" );
77+ }
78+
79+ }
80+ catch ( Exception e ) {
81+ }
82+ }
83+
84+ public void deposit () {
85+
86+ System .out .print ("\n Enter amount to deposit - " );
87+ Scanner sc = new Scanner (System .in );
88+ float amount = sc .nextFloat ();
89+
90+ try {
91+ if ( amount <= 100000f ) {
92+ transactions ++;
93+ balance += amount ;
94+ System .out .println ("\n Successfully Deposited" );
95+ String str = amount + " Rs deposited\n " ;
96+ transactionHistory = transactionHistory .concat (str );
97+ }
98+ else {
99+ System .out .println ("\n Sorry...Limit is 100000.00" );
100+ }
101+
102+ }
103+ catch ( Exception e ) {
104+ }
105+ }
106+
107+ public void transfer () {
108+
109+ Scanner sc = new Scanner (System .in );
110+ System .out .print ("\n Enter Receipent's Name - " );
111+ String receipent = sc .nextLine ();
112+ System .out .print ("\n Enter amount to transfer - " );
113+ float amount = sc .nextFloat ();
114+
115+ try {
116+ if ( balance >= amount ) {
117+ if ( amount <= 50000f ) {
118+ transactions ++;
119+ balance -= amount ;
120+ System .out .println ("\n Successfully Transfered to " + receipent );
121+ String str = amount + " Rs transfered to " + receipent + "\n " ;
122+ transactionHistory = transactionHistory .concat (str );
123+ }
124+ else {
125+ System .out .println ("\n Sorry...Limit is 50000.00" );
126+ }
127+ }
128+ else {
129+ System .out .println ("\n Insufficient Balance" );
130+ }
131+ }
132+ catch ( Exception e ) {
133+ }
134+ }
135+
136+ public void checkBalance () {
137+ System .out .println ("\n " + balance + " Rs" );
138+ }
139+
140+ public void transHistory () {
141+ if ( transactions == 0 ) {
142+ System .out .println ("\n Empty" );
143+ }
144+ else {
145+ System .out .println ("\n " + transactionHistory );
146+ }
147+ }
148+ }
149+
150+
151+ public class AtmInterface {
152+
153+
154+ public static int takeIntegerInput (int limit ) {
155+ int input = 0 ;
156+ boolean flag = false ;
157+
158+ while ( !flag ) {
159+ try {
160+ Scanner sc = new Scanner (System .in );
161+ input = sc .nextInt ();
162+ flag = true ;
163+
164+ if ( flag && input > limit || input < 1 ) {
165+ System .out .println ("Choose the number between 1 to " + limit );
166+ flag = false ;
167+ }
168+ }
169+ catch ( Exception e ) {
170+ System .out .println ("Enter only integer value" );
171+ flag = false ;
172+ }
173+ };
174+ return input ;
175+ }
176+
177+
178+ public static void main (String [] args ) {
179+
180+ System .out .println ("\n **********WELCOME TO SBI ATM SYSTEM**********\n " );
181+ System .out .println ("1.Register \n 2.Exit" );
182+ System .out .print ("Enter Your Choice - " );
183+ int choice = takeIntegerInput (2 );
184+
185+ if ( choice == 1 ) {
186+ BankAccount b = new BankAccount ();
187+ b .register ();
188+ while (true ) {
189+ System .out .println ("\n 1.Login \n 2.Exit" );
190+ System .out .print ("Enter Your Choice - " );
191+ int ch = takeIntegerInput (2 );
192+ if ( ch == 1 ) {
193+ if (b .login ()) {
194+ System .out .println ("\n \n **********WELCOME BACK " + b .name + " **********\n " );
195+ boolean isFinished = false ;
196+ while (!isFinished ) {
197+ System .out .println ("\n 1.Withdraw \n 2.Deposit \n 3.Transfer \n 4.Check Balance \n 5.Transaction History \n 6.Exit" );
198+ System .out .print ("\n Enter Your Choice - " );
199+ int c = takeIntegerInput (6 );
200+ switch (c ) {
201+ case 1 :
202+ b .withdraw ();
203+ break ;
204+ case 2 :
205+ b .deposit ();
206+ break ;
207+ case 3 :
208+ b .transfer ();
209+ break ;
210+ case 4 :
211+ b .checkBalance ();
212+ break ;
213+ case 5 :
214+ b .transHistory ();
215+ break ;
216+ case 6 :
217+ isFinished = true ;
218+ break ;
219+ }
220+ }
221+ }
222+ }
223+ else {
224+ System .exit (0 );
225+ }
226+ }
227+ }
228+ else {
229+ System .exit (0 );
230+ }
231+
232+
233+
234+ }
235+ }
236+
0 commit comments