0% found this document useful (0 votes)
14 views6 pages

Sol TD3 Java

The document defines classes for a banking application including Account, Client, Agency, and PayingAccount classes. It then creates sample data by initializing 4 clients with various account types at an agency, performs some transactions, and prints out lists of clients, savings accounts, and paying accounts.

Uploaded by

NORA LAHSUNI
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
14 views6 pages

Sol TD3 Java

The document defines classes for a banking application including Account, Client, Agency, and PayingAccount classes. It then creates sample data by initializing 4 clients with various account types at an agency, performs some transactions, and prints out lists of clients, savings accounts, and paying accounts.

Uploaded by

NORA LAHSUNI
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 6

UNIVERSITE IBN ZOHR SMI5

Faculté des sciences – Département Informatique « M31 : Conception Orientée Objets »

TD/TP 3

public class Compte {

private String code;


protected double solde;
protected Agence lAgence;
protected Client proprietaire;

public Compte(Client leProproetaire, Agence agence){


this.solde = 0;
this.proprietaire = leProproetaire;
this.lAgence = agence;
}

public Compte(double leSolde, Client leProproetaire, Agence agence){


this.solde = leSolde;
this.proprietaire = leProproetaire;
this.lAgence = agence;
}

public void setCode(String code) {this.code = code;}


public String getCode() {return code;}
public void retirer(double som) {if(som<solde) solde -= som;}
public void deposer(double som) {solde += som;}
}

public class Compte {

private String code;


protected double solde;
protected Agence lAgence;
protected Client proprietaire;

public Compte(Client leProproetaire, Agence agence){


this.solde = 0;
this.proprietaire = leProproetaire;
this.lAgence = agence;
}

public Compte(double leSolde, Client leProproetaire, Agence agence){


this.solde = leSolde;
this.proprietaire = leProproetaire;
this.lAgence = agence;
}

public void setCode(String code) {this.code = code;}


public String getCode() {return code;}
public void retirer(double som) {if(som<solde) solde -= som;}
public void deposer(double som) {solde += som;}

public class ComptePayant extends Compte{

public static int nbComptesP = 0;


private final static double TAUX_OPERATION = 5;

public ComptePayant(Client leProproetaire, Agence agence){


super(leProproetaire, agence);
String code = this.getClass().getName()+":"+ ++nbComptesP;
setCode(code);
}

public ComptePayant(double leSolde, Client leProproetaire, Agence agence){


super(leSolde, leProproetaire, agence);
String code = this.getClass().getName()+":"+ ++nbComptesP;
setCode(code);
}

public void retirer(double som) {super.retirer(som+TAUX_OPERATION);}


public void deposer(double som) {super.deposer(som-TAUX_OPERATION);}

public String toString() {


String s =
"\t| "+getCode()+" | Solde: "+solde+" DH | Montant de l'operation:
"+TAUX_OPERATION + " |" +
"\n\t--------------------------------------------------------------------
---" ;
return s;
}

public class Client {

public final static int NB_MAX_COMPTES = 4;


private int nbComptes = 0;
private static int nbClients = 0;
private String code;
private String nom;
private String prenom;
private String adresse;
private Agence monAgence;
private Compte[] mesComptes;

2/5
public Client(Agence agence){
code = this.getClass().getName()+":"+ ++nbClients;
monAgence = agence;
mesComptes = new Compte[NB_MAX_COMPTES];
}

public Client(Agence agence, String nom, String prenom, String adresse){


code = this.getClass().getName()+":"+ ++nbClients;
monAgence = agence;
this.nom = nom;
this.prenom = prenom;
this.adresse = adresse;
mesComptes = new Compte[NB_MAX_COMPTES];
}

public void addCompte(Compte newCompte){


if(nbComptes < NB_MAX_COMPTES) mesComptes[nbComptes++] = newCompte;
else System.out.println("Erreur");
}

public boolean deposer(int numCompte, double som){


if(numCompte>=0 && numCompte<nbComptes){
mesComptes[numCompte].deposer(som);
return true;
}
return false;
}

public boolean retirer(int numCompte, double som){


if(numCompte>=0 && numCompte<nbComptes){
mesComptes[numCompte].retirer(som);
return true;
}
return false;
}

public Compte getCompte(int numCompte){


if(numCompte>=0 && numCompte<nbComptes){
return mesComptes[numCompte];
}
return null;
}

public int getNbComptes() {return nbComptes;}


public String getCode() {return code;}

public String toString() {


String s = "\n" +
"------------------------------------------------------------------------
-------\n" +
"| "+getCode()+" | "+nom+" | "+prenom+" | @: "+adresse + " |" +
3/5
"\n----------------------------------------------------------------------
---------" ;
return s;
}
}
public class Agence {

public final static int NB_MAX_COMPTES = 80;


public final static int NB_MAX_CLIENTS = 20;
private static int nbAgences = 0;
private static int nbClients = 0;
private static int nbComptes = 0;
private String numero;
private String adresse;
private Client[] lesClients;
private Compte[] lesComptes;

public Agence(String adresse){


numero = this.getClass().getName()+":"+ ++nbAgences;
this.adresse = adresse;
lesClients = new Client[NB_MAX_CLIENTS];
lesComptes = new Compte[NB_MAX_COMPTES];
}

public Compte getCompte(int numCompte) {


if(numCompte>=0 && numCompte<nbComptes){
return lesComptes[numCompte];
}
return null;
}
public void addCompte(Compte newCompte){
if(nbComptes<NB_MAX_COMPTES) lesComptes[nbComptes++] = newCompte;
}

public Client getClient(int numClient) {


if(numClient>=0 && numClient<nbClients){
return lesClients[numClient];
}
return null;
}

public void addClient(Client newClient){


if(nbClients<NB_MAX_CLIENTS) lesClients[nbClients++] = newClient;

public static int getNbComptes() {return nbComptes;}


public static int getNbClients() {return nbClients;}

4/5
public class ApplicationBancaire {

public final static int NB_CLIENTS = 4;

public static void main(String[] args){

/*(a) Création de l'agence */


Agence lAgence = new Agence("N 20, Rue Nassim, Hay Dakhla, Agadir");

/*(b) Création des clients et de leurs comptes*/


Client[] lesClients = new Client[NB_CLIENTS];
String nom, prenom, adresse;
for(int i=0; i<NB_CLIENTS; i++){
nom = "NOM_"+(i+1);
prenom = "Prenom_"+(i+1);
adresse = "Rue N "+(i+1)+", Boulvard "+(i+1);
lesClients[i] = new Client(lAgence,nom,prenom,adresse);
}

/*for(int i=0; i<lesClients.length; i++)


lesClients[i].toString();*/

/* Client 1 */
lesClients[0].addCompte(new CompteEpargne(1000,lesClients[0],lAgence));

/* Client 2 */
lesClients[1].addCompte(new ComptePayant(2500,lesClients[1],lAgence));

/* Client 3 */
lesClients[2].addCompte(new ComptePayant(lesClients[2],lAgence));
lesClients[2].addCompte(new ComptePayant(3000,lesClients[2],lAgence));

/* Client 4 */
lesClients[3].addCompte(new CompteEpargne(2300,lesClients[3],lAgence));
lesClients[3].addCompte(new ComptePayant(lesClients[3],lAgence));

/*(c) Déposer de l'argent */


if(lesClients[0].getCompte(0) != null)
lesClients[0].getCompte(0).deposer(500);
else System.out.println("Ce compte n'existe pas !");

/*(d) Retirer de l'argent */


if(lesClients[2].getCompte(1) != null)
lesClients[2].getCompte(1).retirer(100);
else System.out.println("Ce compte n'existe pas !");

/*(e) Ajout des clients et de leurs comptes à l'agence */


for(int i=0; i<NB_CLIENTS; i++){
lAgence.addClient(lesClients[i]);
for(int j=0; j<lesClients[i].getNbComptes(); j++){
5/5
lAgence.addCompte(lesClients[i].getCompte(j));
}
}

/*(f) Appliquation de la méthode CalculIntérêt sur tous les comptes


d’épargne */
for(int i=0; i<Agence.getNbComptes(); i++)
if(lAgence.getCompte(i) instanceof CompteEpargne)
((CompteEpargne)lAgence.getCompte(i)).calculInteret();

/***(g) Affichage ***/


// Liste des différents clients avec leurs différents comptes
System.out.println("--- Liste des differents clients avec leurs
differents comptes ---");
Client client;
for(int i=0; i<Agence.getNbClients(); i++){
client = lAgence.getClient(i);
System.out.println(client.toString());
for(int j=0; j<client.getNbComptes(); j++)
System.out.println(client.getCompte(j).toString());
}

// Liste des comptes d’épargne de l’agence


System.out.println("\n--- Liste des comptes d epargne de l agence ---");
for(int i=0; i<Agence.getNbComptes(); i++)
if(lAgence.getCompte(i) instanceof CompteEpargne)
System.out.println(lAgence.getCompte(i).toString());

// Liste des comptes payants de l’agence


System.out.println("\n--- Liste des comptes payants de l agence ---");
for(int i=0; i<Agence.getNbComptes(); i++)
if(lAgence.getCompte(i) instanceof ComptePayant)
System.out.println(lAgence.getCompte(i).toString());
}

6/5

You might also like