Co-authored-by: Fastium <Fastium@users.noreply.github.com>

This commit is contained in:
Rémi Heredero 2022-05-04 10:15:11 +02:00
parent 1b82038a15
commit b8951031cd
7 changed files with 68 additions and 9 deletions

12
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,12 @@
{
"configurations": [
{
"type": "java",
"name": "Launch BankController",
"request": "launch",
"mainClass": "bank.BankController",
"projectName": "Lab15_OOP_90898795",
"vmArgs": "-enableassertions"
}
]
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -8,18 +8,27 @@ public abstract class BankAccount {
return balance;
}
public void deposit(double amount){
if(amount<0){
error("cannot deposit this amount !");
return;
}
balance += amount;
}
public boolean withdraw(double amount){
if(balance<amount){
System.out.println("Problem : cannot withdraw that amount");
return false;
return error("cannot withdraw this amount !");
}
balance -= amount;
return true;
}
protected boolean error(String text){
System.out.println("Problem : " + text);
return false;
}
@Override
public String toString() {
return owner + " have " + balance + "CHF on his account.";

View File

@ -3,15 +3,40 @@ package bank;
public class Checking extends BankAccount{
private double minBalance;
Checking(String owner, double amount, double minBalance){
protected Checking(String owner, double amount, double minBalance){
if(owner==null){
error("An account have to be an owner");
return;
}
if(amount<minBalance){
error("Not enough money");
return;
}
if(minBalance>0){
error("Min balance can't be positive");
return;
}
this.owner = owner;
this.balance = amount;
this.minBalance = minBalance;
}
public void setMinBalance(double minBalance) {
protected void setMinBalance(double minBalance) {
if(minBalance>0){
error("Min balance can't be positive");
return;
}
this.minBalance = minBalance;
}
public double getMinBalance() {
return minBalance;
}
@Override
public boolean withdraw(double amount){
if((balance-minBalance)<amount){
return error("cannot withdraw this amount !");
}
balance -= amount;
return true;
}
}

View File

@ -5,13 +5,26 @@ import java.util.Date;
public class Savings extends BankAccount{
private double interestRate;
Savings(String owner, double amount, double interestRate){
protected Savings(String owner, double amount, double interestRate){
if(owner==null){
error("An account have to be an owner");
return;
}
if(amount<0) {
error("A Saving account can't have a negative amount");
return;
}
if(interestRate<0){
error("cannot have interest negative");
return;
}
this.owner = owner;
this.balance = amount;
this.interestRate = interestRate;
}
public double calcInterest(Date a, Date b){
int day = DateUtils.nDays(a, b);
return interestRate * (day/360.0);
protected double calcInterest(Date a, Date b){
double days = DateUtils.nDays(a, b);
return balance * interestRate * (days/360.0);
}
}