Vous êtes sur la page 1sur 5

Programmation orientée objet Mme Eya Cheikh

CORRECTION DU TD1 :
PROGRAMMATION ORIENT EE OBJET

Exercice 1
class Stage {
private int numStage;
private static int nbStage;
private Etudiant Etud;
private Date dateSoutenance;
protected float noteSoutenance;
protected float noteRapport;
public String entreprise;

public Stage(Etudiant E, String Entre) {


Etud = E;
entreprise = Entre;
nbStage++;
numStage=nbStage ;}

public void setDateSoutenance(Date d) {


dateSoutenance = d;
}
public void setResultat(float ns, float nr) {
noteSoutenance = ns;
noteRapport = nr;
}
public boolean EstValidé() {
return (noteSoutenance * 0.4f + noteRapport * 0.6f) >= 10.f;
}

1 L2- Département Tech. Info ISET RADES


Programmation orientée objet Mme Eya Cheikh

public void affiche() {


System.out.println("le numéro de stage est " + numStage + "\n"+"l'étudiant est:
"+Etud.toString() + "\n"+"La date est "+ dateSoutenance.toString() + "\n"+"La date de
soutenance est "+noteSoutenance + " \n" +"La date du rapport est"+ noteRapport);
}}
Exercice 2
class Personne
{ private String Nom;
private String Prenom;
private String profession;
private int age:
public void sePresenter( )
{System.out.println("nom :"+nom+" prénom :"+prenom+" profession :" +profession);
}
public String get_Nom()
{ return Nom; }
public String get_Prenom()
{ return Prenom; }
public Personne(String n,String p)
{Nom=n;
Prenom=p; }
public static void main(String [] args)
{ Personne[ ]TabPersonne=new Personne[3];
TabPersonne[0]=new Personne("Besbes","Ahmed");
TabPersonne[1]=new Personne("Ben zekri","Sami");
TabPersonne[2]=new Personne("Torjmen","Fahd");
for (int i=0;i<3;i++)
System.out.println("(Nom="+TabPersonne[i].get_Nom()+","+"Prenom="+
TabPersonne[i].get_Prenom()+")");
}}

2 L2- Département Tech. Info ISET RADES


Programmation orientée objet Mme Eya Cheikh

Exercice 3
Résultat : 2 et 2

Exercice 4
Question 1
public class Etud_Coureur {
private int numEtud;
private static int nombre;
private String nomPrénom;
private boolean aDéjaParticipé;
private int durée;
public Etud_Coureur(String np)
{this.nombre++;
numEtud=nombre;
this.nomPrénom=np ;}
public int getDurée()
{return this.durée;} public
void setDurée(int d)
{ this.durée=d;}
public boolean getParticipé()
{return this.aDéjaParticipé;}
public void setParticipé(boolean p)
{ this.aDéjaParticipé=p;}
public boolean comparer(Etud_Coureur e)
{return this.durée<=e.durée;}
public String toString()
{ if(this.aDéjaParticipé)
return this.numEtud+this.nomPrénom+" a déjà participé avec une durée de
"+this.durée;
else return this.numEtud+this.nomPrénom+" participe pour la première fois
";}}

3 L2- Département Tech. Info ISET RADES


Programmation orientée objet Mme Eya Cheikh

Question 2
public class Compétition {
private String désignationComp;
private String dateComp;
private final int RECORD_A_BATTRE=132;
private Etud_Coureur[] tabEtud ;
private int nombreCoureur;
public Compétition(String dc, String d)
{this.désignationComp=dc ;
this.dateComp=d;
tabEtud==new Etud_Coureur[20];}
public boolean ajouterCoureur(Etud_Coureur e)
{ boolean succès=false;
If( nombreCoureur<tabEtud.length && (!e.getParticipé())
{ tabEtud[nombreCoureur]=e;
this.nombreCoureur++;
e.setParticipé(true);
succès=true;
}
return succès;}
public Etud_Coureur getMedailleOr()
{ Etud_Coureur e=tabEtud[0];
for(int i =1;i<nombreCoureur;i++)
{ if(tabEtud[i].comparer(e))
{ e=tabEtud[i]; } }
return e;}
public boolean recordBattu( )
{return getMedailleOr().getDurée()<=RECORD_A_BATTRE;} public
void afficher()

4 L2- Département Tech. Info ISET RADES


Programmation orientée objet Mme Eya Cheikh

{String ch=this.désignationComp+this.dateComp+getMedailleOr().toString();
if(recordBattu())
ch+="A battu le record";
System.out.println(ch);}}

import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Compétition c=new Compétition("ISET2015","12/11/2015");
Scanner s=new Scanner(System.in);
for(int i=0;i<20;i++)
{Etud_Coureur e;
System.out.println("Donner le nom et le prénom");
String nom_Prénom=s.next();
e=new Etud_Coureur(nom_Prénom);

System.out.println("Donner la durée réalisée dans la compétion ISET 2015");


int d=s.nextInt();
e.setDurée(d);
c.ajouterCoureur(e)
;}
c.afficher(); }}

5 L2- Département Tech. Info ISET RADES

Vous aimerez peut-être aussi