Skip to content

Commit 0e105ed

Browse files
authored
Create Bank.java
This code represents a simple banking application that allows customers to perform various banking operations It defines a class Account that represents a bank account with attributes like balance, previous transaction, customer name, and customer ID. The class includes methods for depositing, withdrawing, and viewing the previous transaction. The start method in the Account class serves as the main interaction point with the user. It displays a menu of options for checking the balance, depositing, withdrawing, viewing the previous transaction, and exiting. It repeatedly prompts the user for their choice until they choose to exit. The Bank class is the main class of the program. It creates three instances of the Account class, each representing a different customer's account. Users are prompted to enter a PIN, and based on the PIN entered, one of the customer accounts is accessed using the start method. The program provides a simple text-based interface for customers to interact with their accounts. It demonstrates basic object-oriented programming principles and user interaction with a console-based banking application.
1 parent 0324520 commit 0e105ed

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

Bank.java

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package main;
2+
3+
import java.util.Scanner;
4+
5+
class Account{
6+
7+
int balance;
8+
int prevTrans;
9+
String custName;
10+
int custId;
11+
Scanner sc =new Scanner(System.in);
12+
13+
void deposit(int amt1) {
14+
if(amt1 !=0) {
15+
balance= balance+amt1;
16+
prevTrans = amt1;
17+
}
18+
}
19+
20+
void withdraw(int amt2) {
21+
if(balance !=0) {
22+
balance = balance-amt2;
23+
prevTrans = -amt2;
24+
}
25+
}
26+
27+
void getPrevTrans() {
28+
29+
if(prevTrans>0) {
30+
System.out.println("Deposited Amount: "+prevTrans);
31+
}
32+
else if(prevTrans<0) {
33+
System.out.println("Withdrawn Amount: "+Math.abs(prevTrans));
34+
}
35+
else {
36+
System.out.println("No Previous Transaction ");
37+
}
38+
39+
}
40+
41+
void start() {
42+
int z=0;
43+
System.out.println("Greetings "+custName+"\nID : "+custId+"\n");
44+
System.out.println("What do you wish to do today?\n");
45+
System.out.println("1. Check Balance\n2. Deposit\n3. Withdraw\n4. View Previous Transaction\n5. Exit \n");
46+
47+
do {
48+
System.out.println("******************");
49+
System.out.println("Enter your choice: ");
50+
System.out.println("******************");
51+
z=sc.nextInt();
52+
53+
switch(z) {
54+
55+
case 1:
56+
System.out.println("---------------");
57+
System.out.println("Current Balance : "+balance);
58+
System.out.println("---------------\n");
59+
break;
60+
61+
case 2:
62+
System.out.println("------------------------");
63+
System.out.println("Enter amount to deposit:");
64+
System.out.println("------------------------");
65+
int a=sc.nextInt();
66+
deposit(a);
67+
System.out.println("\n");
68+
break;
69+
70+
case 3:
71+
System.out.println("-------------------------");
72+
System.out.println("Enter amount to withdraw:");
73+
System.out.println("-------------------------");
74+
int b=sc.nextInt();
75+
withdraw(b);
76+
System.out.println("\n");
77+
break;
78+
79+
case 4:
80+
System.out.println("-------------------------");
81+
System.out.println("Previous Transaction : ");
82+
getPrevTrans();
83+
System.out.println("-------------------------\n");
84+
break;
85+
86+
case 5:
87+
System.out.println("*******************************");
88+
break;
89+
90+
default:
91+
System.out.println("INVALID INPUT! \nPlease try again ");
92+
break;
93+
}
94+
95+
}while(z!=5);
96+
System.out.println("Thank you for using our services");
97+
}
98+
}
99+
100+
public class Bank {
101+
public static void main(String[] args) {
102+
103+
104+
Account b1=new Account();
105+
b1.custId= 9934823;
106+
b1.custName="Paras Dongre";
107+
b1.balance= 52000;
108+
109+
Account b2=new Account();
110+
b2.custId= 7842464;
111+
b2.custName="Rahul Bhage";
112+
b2.balance= 72000;
113+
114+
Account b3=new Account();
115+
b3.custId= 532568;
116+
b3.custName="Anshul Pagle";
117+
b3.balance= 34000;
118+
119+
System.out.println(" WELCOME TO THE PHD BANK");
120+
System.out.println(" ***********************\nEnter your pin : ");
121+
122+
Scanner s=new Scanner(System.in);
123+
int pin=s.nextInt();
124+
125+
if(pin==1234) {
126+
b1.start();
127+
}
128+
else if(pin==4321) {
129+
b2.start();
130+
}
131+
else if(pin==9876) {
132+
b3.start();
133+
}
134+
else {
135+
System.out.println("Invalid PIN !! Try Again");
136+
}
137+
}
138+
}

0 commit comments

Comments
 (0)