-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram6.java
More file actions
66 lines (62 loc) · 1.9 KB
/
program6.java
File metadata and controls
66 lines (62 loc) · 1.9 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
import java.util.*;
abstract class Bank{
protected String name;
protected long accountno;
protected double balance;
void readDetails(Scanner sc){
System.out.println("Enter name:");
name = sc.nextLine();
System.out.println("Enter account no");
accountno = sc.nextLong();
System.out.println("Enter Balance:");
balance = sc.nextDouble();
sc.nextLine();
}
void displayDetails(){
System.out.println("Bank Name"+name);
System.out.println("Account Number"+accountno);
System.out.println("Balance"+balance);
}
abstract void calculateInterest();
}
class CityBank extends Bank{
@Override
void calculateInterest(){
double interest = balance*0.05;
System.out.println("Interest earned by City banK"+interest);
}
}
class Axis extends Bank{
@Override
void calculateInterest(){
double interest = balance*0.07;
System.out.println("Interest earned by Axis"+interest);
}
}
class SBI extends Bank{
@Override
void calculateInterest(){
double interest = balance*0.02;
System.out.println("Interest earned by SBI"+interest);
}
}
public class program6 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
CityBank cb = new CityBank();
SBI sbi = new SBI();
Axis axis = new Axis();
System.out.println("Citybank account holder:");
cb.readDetails(sc);
cb.displayDetails();
cb.calculateInterest();
System.out.println("Axis account holder:");
axis.readDetails(sc);
axis.displayDetails();
axis.calculateInterest();
System.out.println("SBI account holder:");
sbi.readDetails(sc);
sbi.displayDetails();
sbi.calculateInterest();
}
}