Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
jenny931224 authored Dec 29, 2019
1 parent d83acff commit 0541227
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 0 deletions.
Binary file added Session7/BankSystem/bin/lk/ac/pdn/Account.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
39 changes: 39 additions & 0 deletions Session7/BankSystem/src/lk/ac/pdn/Account.java
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);
}
}
25 changes: 25 additions & 0 deletions Session7/BankSystem/src/lk/ac/pdn/AccountDriver.java
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();
}

}
27 changes: 27 additions & 0 deletions Session7/BankSystem/src/lk/ac/pdn/KidsAccount.java
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;
}

}
}
58 changes: 58 additions & 0 deletions Session7/BankSystem/src/lk/ac/pdn/RetirementAccount.java
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());
}
}
38 changes: 38 additions & 0 deletions Session7/BankSystem/src/lk/ac/pdn/SavingsAccount.java
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());
}
}

0 comments on commit 0541227

Please sign in to comment.