work on class 05/05
This commit is contained in:
@@ -1,12 +1,25 @@
|
||||
package bank;
|
||||
|
||||
/**
|
||||
* Create a bank account with a balance and a owner
|
||||
*/
|
||||
public abstract class BankAccount {
|
||||
protected double balance;
|
||||
protected String owner;
|
||||
|
||||
/**
|
||||
* Get balance of the account
|
||||
* @return the balance of the account
|
||||
*/
|
||||
public double getBalance() {
|
||||
return balance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deposit an amount on your account
|
||||
* Check the amount for accept only positive amount.
|
||||
* @param amount
|
||||
*/
|
||||
public void deposit(double amount){
|
||||
if(amount<0){
|
||||
error("cannot deposit this amount !");
|
||||
@@ -14,6 +27,13 @@ public abstract class BankAccount {
|
||||
}
|
||||
balance += amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Withdraw an amount on your account
|
||||
* Check the amount for be sure you have this money
|
||||
* @param amount The amount you want to withdraw
|
||||
* @return true : if the withdraw has been done
|
||||
*/
|
||||
public boolean withdraw(double amount){
|
||||
if(balance<amount){
|
||||
return error("cannot withdraw this amount !");
|
||||
@@ -22,15 +42,21 @@ public abstract class BankAccount {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Explain the problem, if something is wrong
|
||||
* @param text
|
||||
* @return the explanation of the problem
|
||||
*/
|
||||
protected boolean error(String text){
|
||||
System.out.println("Problem : " + text);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Rewrite the bank account to string
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return owner + " have " + balance + "CHF on his account.";
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,8 +1,18 @@
|
||||
package bank;
|
||||
|
||||
/**
|
||||
* Create a bank account with specification :
|
||||
* -
|
||||
*/
|
||||
public class Checking extends BankAccount{
|
||||
private double minBalance;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param owner
|
||||
* @param amount
|
||||
* @param minBalance
|
||||
*/
|
||||
protected Checking(String owner, double amount, double minBalance){
|
||||
if(owner==null){
|
||||
error("An account have to be an owner");
|
||||
@@ -20,6 +30,11 @@ public class Checking extends BankAccount{
|
||||
this.balance = amount;
|
||||
this.minBalance = minBalance;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param minBalance
|
||||
*/
|
||||
protected void setMinBalance(double minBalance) {
|
||||
if(minBalance>0){
|
||||
error("Min balance can't be positive");
|
||||
@@ -27,10 +42,18 @@ public class Checking extends BankAccount{
|
||||
}
|
||||
this.minBalance = minBalance;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public double getMinBalance() {
|
||||
return minBalance;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public boolean withdraw(double amount){
|
||||
if((balance-minBalance)<amount){
|
||||
|
@@ -3,8 +3,18 @@ package bank;
|
||||
import hevs.utils.DateUtils;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class Savings extends BankAccount{
|
||||
private double interestRate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param owner
|
||||
* @param amount
|
||||
* @param interestRate
|
||||
*/
|
||||
protected Savings(String owner, double amount, double interestRate){
|
||||
if(owner==null){
|
||||
error("An account have to be an owner");
|
||||
@@ -23,6 +33,12 @@ public class Savings extends BankAccount{
|
||||
this.interestRate = interestRate;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param a
|
||||
* @param b
|
||||
* @return
|
||||
*/
|
||||
protected double calcInterest(Date a, Date b){
|
||||
double days = DateUtils.nDays(a, b);
|
||||
return balance * interestRate * (days/360.0);
|
||||
|
Reference in New Issue
Block a user