-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountMain.java
More file actions
142 lines (124 loc) · 4.39 KB
/
Copy pathAccountMain.java
File metadata and controls
142 lines (124 loc) · 4.39 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
import java.util.Scanner;
import java.lang.Math;
class Account{
protected String cname;
protected int acno;
protected String tac;
protected double bal;
public Account(){
cname = "";
acno = 0;
tac = "";
bal = 0;
}
public Account(String cname, int acno, String tac, double bal){
this.cname = cname;
this.acno = acno;
this.tac = tac;
this.bal = bal;
}
public void display(){
System.out.println("Customer name is: " + this.cname);
System.out.println("Customer account number is: " + this.acno);
System.out.println("Account type is: " + this.tac);
System.out.println("Account balance is: " + this.bal);
}
void displayBalance(){
System.out.println("Account balance is: " + this.bal);
}
void deposit(double amt){
this.bal += amt;
System.out.println("Amount Deposited = " + amt);
displayBalance();
}
}
class SavingAC extends Account{
private final double irate = 0.06;
SavingAC(String cname, int acno, String tac, double bal){
super(cname, acno, tac, bal);
}
void toComputeInt(int nyear){
double iamt = this.bal * Math.pow(1 + irate, nyear) - this.bal;
deposit(iamt);
}
void withdraw(double amt){
if (amt <= this.bal){
bal -= amt;
System.out.println("Amount Withdrawn: " + amt);
checkMinBal();
} else{
System.out.println("Insufficient balance to withdraw.");
}
}
void checkMinBal(){
if (this.bal < 1000){
System.out.println("Penalty of Rs 100 due to balance below minimum.");
bal -= 100;
displayBalance();
}
}
}
class CurrentAC extends Account{
CurrentAC(String cname, int acno, String tac, double bal) {
super(cname, acno, tac, bal);
}
void withdraw(double amt){
if (amt <= (bal + 50000)){
bal -= amt;
System.out.println("Amount Withdrawn: " + amt);
checkMinBal();
} else{
System.out.println("Withdrawal limit exceeded.");
}
}
void checkMinBal(){
if (bal < -50000){
System.out.println("Penalty of Rs 5000 due to overdraft.");
bal -= 5000;
displayBalance();
}
}
}
class AccountMain{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Please enter how many accounts you want to store:");
int n = sc.nextInt();
sc.nextLine();
Account[] A = new Account[n];
for(int i = 0; i < n; i++){
System.out.println("Please enter account holder name:");
String cname = sc.nextLine();
System.out.println("Please enter account number:");
int acno = sc.nextInt();
sc.nextLine();
System.out.println("Please enter account type Saving/Current:");
String tac = sc.nextLine();
System.out.println("Please enter account balance:");
double bal = sc.nextDouble();
if(tac.equalsIgnoreCase("Saving")){
System.out.println("Please enter the number of years for interest calculation:");
int nyear = sc.nextInt();
System.out.println("Please enter amount you want to withdraw:");
double amt = sc.nextDouble();
A[i] = new SavingAC(cname, acno, tac, bal);
((SavingAC) A[i]).toComputeInt(nyear);
((SavingAC) A[i]).withdraw(amt);
}else if(tac.equalsIgnoreCase("Current")){
System.out.println("Please enter amount to withdraw:");
double amt = sc.nextDouble();
A[i] = new CurrentAC(cname, acno, tac, bal);
((CurrentAC) A[i]).withdraw(amt);
}else{
System.out.println("Invalid account type. Please enter either 'Saving' or 'Current'.");
i--;
}
sc.nextLine();
}
System.out.println("Bank Information Detail:");
for(int i = 0; i < n; i++){
System.out.println("Account information of person " + (i + 1));
A[i].display();
}
}
}