-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountManager.java
More file actions
85 lines (83 loc) · 2.4 KB
/
AccountManager.java
File metadata and controls
85 lines (83 loc) · 2.4 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
class Account
{
long accountNumber;
String holderName;
double balance;
Account(long accountNumber,String holderName,double balance )
{
this.accountNumber=accountNumber;
this.holderName=holderName;
this.balance=balance;
}
void show()
{
System.out.println("AccountNumber "+accountNumber+" HolderName "+holderName+" Balance "+balance);
}
}
class SavingsAccount extends Account
{
float iR=4;
SavingsAccount(long accountNumber,String holderName,double balance)
{
super(accountNumber,holderName,balance);
}
float calculateYearlyInterest()
{
return (float) ((balance * iR * 1) / 100); // explicit typecasting
}
void show()
{
super.show();
System.out.println("AccountNumber "+accountNumber+" HolderName "+holderName+" Balance "+balance+" Yearly interest Rate "+iR);
}
}
class CurrentAccount extends Account
{
CurrentAccount(long accountNumber,String holderName,double balance)
{
super(accountNumber,holderName,balance);
}
void show()
{
super.show();
System.out.println("AccountNumber "+ accountNumber + " HolderName " + holderName + " Balance" + balance);
}
}
class Manager
{
int noOfAccount=0;
Account acc[]=new Account[5];
void addAccount(Account firstsavingsAcc) {
acc[noOfAccount++] = firstsavingsAcc;
}
void addAccount(CurrentAccount b)
{
acc[noOfAccount++]=b;
}
void show()
{
for(int i=0;i<acc.length;i++)
{
acc[i].show();
}
}
}
class Demo12
{
public static void main(String args[])
{
Account firstsavingsAcc=new SavingsAccount(12345,"Priyangana",5000);
Account secondsavingsAcc=new SavingsAccount(23456,"Riya",6000);
Account firstcurrentAcc=new CurrentAccount(34567,"Priya",7000);
Account secondcurrentAcc=new CurrentAccount(45678,"Avik",4500);
Account thirdcurrentAcc=new CurrentAccount(56789,"Akash",5500);
Manager man=new Manager();
man.addAccount(firstsavingsAcc);
man.addAccount(secondsavingsAcc);
man.addAccount(firstcurrentAcc);
man.addAccount(secondcurrentAcc);
man.addAccount(thirdcurrentAcc);
man.show(); // create show method to display the properties of all the objects accordingly.
// create addAccount class and overwrite it with both the object type parameter SavingsAccount and CurrentAccount, the way we discussed last time in lab.
}
}