forked from rakhi2207/java-programs-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bank.java
136 lines (111 loc) · 4.01 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
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
import java.util.Scanner;
class BankAccount {
protected int account;
protected double balance;
public BankAccount(int account_num, double init_balance) {
account = account_num;
balance = init_balance;
}
// method to deposit into the account
public void deposit(double amount) {
balance += amount;
System.out.println("Deposit into account: " + account);
System.out.println("Amount: " + amount);
System.out.println("New Balance: " + balance);
System.out.println();
}
// method to withdraw from the account
public boolean withdrawal(double amount) {
boolean result = false;
System.out.println("Withdrawal from account: " + account);
System.out.println("Amount: " + amount);
if (amount > balance) {
System.out.println("Insufficient Funds");
} else {
balance -= amount;
System.out.println("New Balance: " + balance);
result = true;
}
System.out.println();
return result;
}
}
class CurrentAccount extends BankAccount {
final SavingsAccount fee;
public CurrentAccount(int account_num, double init_balance, SavingsAccount protection) {
super(account_num, init_balance);
fee = protection;
}
// method for fee deduction
public boolean deductFee(double amount) {
boolean result = false;
if (!super.withdrawal(amount)) {
System.out.println("Using Fee...");
if (!fee.withdrawal(amount)) {
System.out.println("Fee Source Insufficient");
} else {
System.out.println("Using Fee");
balance = 0;
System.out.println("New Balance on account after deduction " + account + ": " + balance);
result = true;
}
}
System.out.println();
return result;
}
}
class SavingsAccount extends BankAccount {
protected double interestRate;
public SavingsAccount(int account_num, double init_balance, double ir) {
super(account_num, init_balance);
interestRate = ir;
}
// method to calculate the interest
public void addInterest() {
balance += balance * interestRate;
System.out.println("Interest added to account: " + account);
System.out.println("New Balance: " + balance);
System.out.println();
}
}
public class bank {
public static void main(String[] args) {
// write your code here
char str;
Scanner input = new Scanner(System.in);
System.out.print("Enter the Account number: ");
int account_num = input.nextInt();
SavingsAccount save = new SavingsAccount(account_num, 1000, 0.5);
CurrentAccount current = new CurrentAccount(account_num, 1000, save);
do {
System.out.println("+++++Welcome to Laxmi Chit Fund+++++");
System.out.println("1. Deposit Money");
System.out.println("2. Withdraw Money");
System.out.print("Enter your choice: ");
int x = input.nextInt();
switch (x) {
case 1:
System.out.print("Enter the amount to be deposit: ");
double deposit = input.nextDouble();
save.deposit(deposit);
break;
case 2:
System.out.print("Enter the amount to be withdrawn: ");
double withdraw = input.nextDouble();
save.withdrawal(withdraw);
break;
default:
}
System.out.print("Do you want to continue: ");
str = input.next().charAt(0);
}while (str == 'y' || str == 'Y');
// System.out.println("Account-1");
// save.deposit(148.04);
// check.withdrawal(123);
//
// System.out.println("Account-2");
// save.withdrawal(725.55);
// check.deposit(1000);
// check.withdrawal(320.18);
}
}