work on class 05/05

This commit is contained in:
2022-05-05 16:12:28 +02:00
parent 9a97e6dfbd
commit 608c59d3e3
16 changed files with 183 additions and 10 deletions

View File

@@ -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.";
}
}
}

View File

@@ -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){

View File

@@ -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);