-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbank.java
More file actions
65 lines (54 loc) · 1.56 KB
/
bank.java
File metadata and controls
65 lines (54 loc) · 1.56 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
class Bank {
String name;
int accno;
double p;
public Bank(String name, int accno, double p) {
this.name = name;
this.accno = accno;
this.p = p;
}
public void display() {
System.out.println("Name: " + name);
System.out.println("Account Number: " + accno);
System.out.println("Principal Amount: " + p);
}
}
class Account extends Bank {
double amt;
public Account(String name, int accno, double p, double amt) {
super(name, accno, p);
this.amt = amt;
}
public void deposit() {
p = p + amt;
}
public void withdraw() {
if (amt > p) {
System.out.println("INSUFFICIENT BALANCE");
} else {
p = p - amt;
if (p < 500) {
double penalty = (500 - p) / 10;
p = p - penalty;
}
}
}
public void display() {
super.display();
System.out.println("Transaction Amount: " + amt);
}
}
public class Main {
public static void main(String[] args) {
Account account = new Account("John Doe", 12345, 1000.0, 300.0);
System.out.println("Before Transaction:");
account.display();
account.deposit();
System.out.println("After Deposit:");
account.display();
account.amt = 800.0; // Modify the transaction amount for withdrawal
account.withdraw();
System.out.println("After Withdrawal:");
account.display();
}
}