Vous êtes sur la page 1sur 3

Correction d’examen National du BTS DSI session Mai 2013 Partie 1 POO

// classe Commande ***************************************


class Commande implements Cloneable {
private int numCom;
private Date dateCom;
private String nomFournisseur;

public Commande(int numCom, Date dateCom, String nomFournisseur) {


this.numCom = numCom;
this.dateCom = dateCom;
this.nomFournisseur = nomFournisseur;
}
public String toString() {
SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yyyy");
return numCom + " , date :" + sdf.format(dateCom) + ", Fournisseur: " + nomFournisseur ;
}
public boolean equals(Object obj) {
Commande c = (Commande) obj;
if (this.numCom != c.numCom) {
return false;
}
return true;
}
public int getNumCom() {
return numCom;
}
public Date getDateCom() {
return dateCom;
}
public String getNomFournisseur() {
return nomFournisseur;
}
public void setNumCom(int numCom) {
this.numCom = numCom;
}
public void setDateCom(Date dateCom) {
this.dateCom = dateCom;
}
public void setNomFournisseur(String nomFournisseur) {
this.nomFournisseur = nomFournisseur;
}
protected Commande clone() {
Commande c=null;
try{
c=(Commande) super.clone();
}

Correction proposée par Pr H.Laaraj Page 1 sur 3


Correction d’examen National du BTS DSI session Mai 2013 Partie 1 POO

catch(CloneNotSupportedException e){
System.err.println(e);
}
return c;
}
}
//Class Client *************************************
class Client {
protected String code;
protected String nom;
protected String adresse;
protected String tel;
protected Vector<Commande> listCommandes;

public Client(String code, String nom, String adresse) {


this.code = code;
this.nom = nom;
this.adresse = adresse;
listCommandes=new Vector<Commande>();
}
public boolean enregistrerCommande (Commande cmd)
{
if(!listCommandes.contains(cmd)) {
listCommandes.add(cmd);
return true;
}
return false;
}

public boolean supprimerCommande (int position)


{
for (int i=0;i<listCommandes.size();i++)
{
if(listCommandes.get(i).getNumCom()==position)
{
listCommandes.remove(i);
return true;
}
}
return false;
}

public String toString() {


String liste="";
for (int i=0;i<listCommandes.size();i++)

Correction proposée par Pr H.Laaraj Page 2 sur 3


Correction d’examen National du BTS DSI session Mai 2013 Partie 1 POO

{
liste = liste + "\n "+listCommandes.get(i);
}
return "Client : " + "code=" + code + ", nom=" + nom + ", adresse=" + adresse +" \n la liste des
Commandes: "+ liste+".";
}

}
//Class ClientFidel******************************************
class ClientFidel extends Client{
String codeFidelite ;
float tauxReduction ;

public ClientFidel( String code, String nom, String adresse,String codeFidelite, float
tauxReduction) {
super(code, nom, adresse);
this.codeFidelite = codeFidelite;
this.tauxReduction = tauxReduction;
}
public String toString() {
return "ClientFidel : " + "codeFidelite=" + codeFidelite + ", tauxReduction=" + tauxReduction +
" "+ super.toString();
}

}
//programme main de test********************************
import java.util.*;
public class MainProg {
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yyyy");
Commande c1=new Commande(1,sdf.parse("26/01/2015"),"lait de lux");
Commande c2=new Commande(2,sdf.parse("09/03/2015"),"infomat");
Client cl1 =new Client("C1","mohammed","App 33 N 4 hay elkassam laayoune");
ClientFidel cl2 =new ClientFidel("C2","khadija","App 12 N 12 CYM rabat","F2",10.3f);
cl1.enregistrerCommande(c1);
cl1.enregistrerCommande(c2);
cl2.enregistrerCommande(c2);
cl2.enregistrerCommande(c2);
System.out.println(cl1);
System.out.println(cl2);
}
}

Correction proposée par Pr H.Laaraj Page 3 sur 3

Vous aimerez peut-être aussi