-
Notifications
You must be signed in to change notification settings - Fork 30
/
bank.java
92 lines (79 loc) · 1.98 KB
/
bank.java
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
import java.util.Scanner;
class Customer {
String name;
long contactno;
static double balance;
Customer() {
super();
}
Customer(String name, long contactno, double balance) {
super();
this.name = name;
this.contactno = contactno;
Customer.balance = balance;
}
void display() {
System.out.println("Name is " + name);
System.out.println("Contct No. is " + contactno);
System.out.println("Balance : " + balance);
}
}
class Withdraw extends Customer {
void withdrawAmount(int amount) {
if (amount <= balance) {
balance = balance - amount;
System.out.println("Amount withdrawn Sucessfull!!");
System.out.println("Amount Withdrawn: " + amount);
} else {
System.out.println("Transaction Failed!!!");
System.out.println("Insufficent Balance..");
}
}
}
class Deposit extends Customer {
void depositAmount(int amount) {
balance = balance + amount;
System.out.println("Amount Deposited Sucessfully!!!");
}
}
class Database {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your name");
String n = sc.next();
System.out.println("Enter your contactno");
long c = sc.nextLong();
int choice;
System.out.println("Give a Starting balance: ");
double startingBalance = sc.nextInt();
Customer ob = new Customer(n, c, startingBalance);
Withdraw w = new Withdraw();
Deposit d = new Deposit();
while (true) {
System.out.println();
System.out.println("1 to Withdraw");
System.out.println("2 to Deposit");
System.out.println("3 to Balance Check");
System.out.println("4 to Exit");
choice = sc.nextInt();
switch (choice) {
case 1:
System.out.println("Enter the amount: ");
w.withdrawAmount(sc.nextInt());
break;
case 2:
System.out.println("Enter the amount: ");
d.depositAmount(sc.nextInt());
break;
case 3:
ob.display();
break;
case 4:
sc.close();
return;
default:
System.out.println("Wrong choice, try again");
}
}
}
}