-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d83acff
commit 0541227
Showing
10 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package lk.ac.pdn; | ||
|
||
public class Account { | ||
public String accountID; | ||
protected String accountHolder; | ||
protected double amount; | ||
|
||
public void setAccHolder(String accHolder) { | ||
this.accountHolder = accHolder; | ||
} | ||
|
||
Account(){ | ||
|
||
}//Default Constructor | ||
|
||
Account(String accountID, String accountHolder, double amount){ | ||
this.accountHolder = accountHolder; | ||
this.accountID = accountID; | ||
this.amount = amount; | ||
} | ||
public void deposit(String depositAmount) { | ||
this.amount += Integer.parseInt(depositAmount); | ||
}//method to deposit amount | ||
|
||
public double withdraw(double w) { | ||
if(w<this.amount) { | ||
amount -=w; | ||
} | ||
return amount; | ||
|
||
}//method to check if withdrawal valid or not | ||
|
||
public void details() { | ||
System.out.println("*****Account Details******\n\n"); | ||
System.out.println("Account ID: " + this.accountID + "\n"); | ||
System.out.println("Account Holder Name: " + this.accountHolder + "\n"); | ||
System.out.println("Amount: " + this.amount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package lk.ac.pdn; | ||
|
||
public class AccountDriver { | ||
|
||
public static void main(String[] args) { | ||
Account account = new Account("ac001","John",50000); | ||
account.deposit("10000"); | ||
account.withdraw(250.5); | ||
account.details(); | ||
|
||
SavingsAccount savings = new SavingsAccount("ac001","John",50000,2000); | ||
savings.withdraw(1500); | ||
savings.details(); | ||
|
||
RetirementAccount retirement = new RetirementAccount("ac001","John",50000); | ||
retirement.setYearOfRetirement(2015); | ||
retirement.setBonusPercent(0.65); | ||
retirement.details(); | ||
|
||
KidsAccount kids = new KidsAccount("ac001","John",50000,2000,"Father"); | ||
kids.withdraw(500,"Father"); | ||
kids.details(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package lk.ac.pdn; | ||
|
||
public class KidsAccount extends SavingsAccount { | ||
KidsAccount(String accountID, String accountHolder, double amount, double withdrawLimit,String guardian) { | ||
super(accountID, accountHolder, amount, withdrawLimit); | ||
this.guardian = guardian; | ||
} | ||
|
||
private String guardian; | ||
|
||
public void setGuardian(String guardian) { | ||
this.guardian = guardian; | ||
} | ||
|
||
public String getGuardian() { | ||
return this.guardian; | ||
} | ||
|
||
public void withdraw(double withdrawAmount, String guardian) { | ||
System.out.println("You can only withdraw if you specify a guardian\n"); | ||
System.out.println("Guardian of child: " + guardian); | ||
if(withdrawAmount<amount && getGuardian() == guardian) { | ||
amount -= withdrawAmount; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package lk.ac.pdn; | ||
|
||
import java.util.Calendar; | ||
|
||
public class RetirementAccount extends Account { | ||
|
||
RetirementAccount(String accountID, String accountHolder, double amount) { | ||
super(accountID, accountHolder, amount); } | ||
|
||
private int yearOfRetirement; | ||
private double bonusPercent; | ||
int year = Calendar.getInstance().get(Calendar.YEAR); | ||
int additionalYears; | ||
|
||
RetirementAccount(int year, double bonusPercent){ | ||
this.yearOfRetirement = year; | ||
this.bonusPercent = bonusPercent; | ||
}// values can be directly assigned using constructor getter setter methods below | ||
|
||
public void setBonusPercent(double bonusPercent) { | ||
this.bonusPercent = bonusPercent; | ||
} | ||
public double getBonusPercent() { | ||
return this.bonusPercent; | ||
} | ||
|
||
public void setYearOfRetirement(int year) { | ||
this.yearOfRetirement = year; | ||
} | ||
|
||
public int getYearOfRetirement() { | ||
return this.yearOfRetirement; | ||
} | ||
|
||
public int calAdditionalYears() { | ||
additionalYears = getYearOfRetirement() - year; | ||
return additionalYears; | ||
} | ||
|
||
public double calculateBonus(double bonus) { | ||
bonus = additionalYears * getBonusPercent(); | ||
return bonus; | ||
} | ||
|
||
public double withdraw(double withdrawAmount, int year) { | ||
System.out.println("Year of retirement: " + getYearOfRetirement()); | ||
if(withdrawAmount<amount && getYearOfRetirement() == year) { | ||
amount -= withdrawAmount; | ||
} | ||
return amount; | ||
} | ||
|
||
public void details() { | ||
super.details(); | ||
System.out.println("Year of Retirement: " + this.getYearOfRetirement()); | ||
System.out.println("Bonus Percent: " + this.getBonusPercent()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package lk.ac.pdn; | ||
|
||
public class SavingsAccount extends Account { | ||
|
||
|
||
protected double withdrawLimit; | ||
|
||
SavingsAccount(String accountID, String accountHolder, double amount,double withdraw) { | ||
super(accountID, accountHolder, amount); | ||
this.withdrawLimit = withdraw; | ||
} | ||
|
||
|
||
public void setWithdrawLimit(double amount) { | ||
this.withdrawLimit = amount; | ||
} | ||
|
||
public double getWithdrawalLimit() { | ||
return withdrawLimit; | ||
} | ||
|
||
@Override | ||
public double withdraw(double withdrawalamount) { | ||
if(withdrawalamount<getWithdrawalLimit() && withdrawalamount<amount) { | ||
amount -=withdrawalamount; | ||
} | ||
return amount; | ||
|
||
} | ||
|
||
|
||
|
||
@Override | ||
public void details() { | ||
super.details(); | ||
System.out.println("Withdrawal Limit: " + this.getWithdrawalLimit()); | ||
} | ||
} |