Correction d’examen National du BTS DSI session Mai 2014  : JAVA 



import java.util.Date; 

public class Tache {    
    private String CodeTache; 
    private String nomTache;     
    private Date DateDebut;     
    private Date DateFin;     
public Tache(String CodeTache,String nomTache,Date     DateDebut,Date DateFin){    
 this.CodeTache=CodeTache;     
 this.nomTache=nomTache;     
 this.DateDebut=DateDebut;     
 this.DateFin=DateFin;     }     
public void setDateDebut(Date d){     DateDebut=d;     } 

public void setDateFin(Date d){     DateFin=d; }  
   
public String toString(){     return "Code : "+CodeTache+", la tache intitulée : "             +nomTache+", Date de début : "             +DateDebut+", Date de fin : "+DateFin;     }   

 public boolean equals(Object Obj){    
 boolean e; Tache T=(Tache)Obj;
if(CodeTache.equals(T.CodeTache))        
      e=true;   
else       
      e=false;    
 return e;     } }  



  
import java.util.Date; 

public class TacheOrdinaire extends Tache{     

private String Description; 
    
public TacheOrdinaire(String CodeTache,String nomTache,Date DateDebut,Date DateFin,String Description){     super(CodeTache,nomTache,DateDebut,DateFin);     this.Description=Description;     }     

public String toString(){    
 return super.toString()+", Description : "+Description;     } }

   
import java.util.Date; 

public class TacheCritique extends Tache{     

private int DelaiMax; 
public TacheCritique(String CodeTache, String nomTache, Date DateDebut, Date DateFin,int DelaiMax) {         
super(CodeTache, nomTache, DateDebut, DateFin);         this.DelaiMax=DelaiMax;     }               

public String toString(){     
return super.toString()+", DelaiMax : "+DelaiMax;    
 }      

   
import java.util.Vector; 

public class Projet {    
private String Code;    
private String nomProjet;    
private Vector<Tache>Liste=new Vector<Tache>(); 
  
public Projet(String Code,String nomProjet){    
this.Code=Code;    
this.nomProjet=nomProjet;    
}        

public void ajouterTache(Tache d){    
if(!Liste.contains(d))        
Liste.add(d);        
}        

public void supprimerTache(int index){        if(Liste.size()-1>=index)    
Liste.removeElementAt(index);    
}     

 public String toString(){    
String Msg=null;    Msg="Code : "+Code+" , Nom projet : "            +nomProjet+"\n La liste des taches de ce projet :\n";    
for(int i=0;i<Liste.size();i++)        Msg+=(Liste.elementAt(i)).toString()+"\n";    return Msg;    
}

public boolean equals(Object Obj){    
    
  Projet P = (Projet)Obj;    boolean b;                  if(this.Code.equals(P.Code))        
      b=true;    
 else        
      b=false;
                
      return b;        
} }  


Classe De Test : 

  

import java.util.Date; 
public class Test {     
public static void main(String[] args){        
Projet P = new Projet("P1","PFE");        
Tache []T=new Tache[2];        
T[0]=new TacheOrdinaire("T1","Conception",new Date(),new Date(),"Conception,Spécification ...");        
T[1]=new TacheCritique("T2","Programmation",new Date(),new Date(),30);        
System.out.println(T[0].toString());       System.out.println(T[1].toString());        
P.ajouterTache(T[0]);        
P.ajouterTache(T[1]);       
System.out.println(P.toString());     
}     
} 

Commentaires