SlideShare une entreprise Scribd logo
UNIVERSITE MOHAMED I
       FACULTE DES SCIENCES                Année Universitaire : 2011/ 2012
         DEPARTEMENT DE                    Filières : SMI
         MATHEMATIQUES                     Semestre : 5 (3ème année)
         ET INFORMATIQUE                   Module : POO
              OUJDA


   CORRECTION DE LA SERIE 3 DU TD DU POO
Exercice 1
Soit le Programme suivant :

      public class TestPoint {
       public static void main (String[] args)
       {
          int n;
          n =Clavier.lireInt();
          switch(n)
          {
          case 0:System.out.println("case 0");
          case 1:
          case 2:System.out.println("case 2");
                    break;
          case 3:System.out.println("case 3");
                    break;
          case 4:
          case 5:System.out.println("case 5");
          default :System.out.println("Autre");
          }
       }
       }
Le résultat de l’exécution de ce Programme dans le cas ou :
          n=0 :
     case 0
     case 2
          n=1 :
     case 2
          n=2 :
     case 2

E-mail : thecomdevteam@gmail.com
WebSite : www.com-dev.net
Phone : +212618037859| +212662516524                                          Page 1
UNIVERSITE MOHAMED I
       FACULTE DES SCIENCES              Année Universitaire : 2011/ 2012
         DEPARTEMENT DE                  Filières : SMI
         MATHEMATIQUES                   Semestre : 5 (3ème année)
         ET INFORMATIQUE                 Module : POO
              OUJDA



          n=3 :
     case 3
          n=4 :
     case 5
     Autre
          n=10 :
     Autre
          n=-5 :
     Autre

Exercice 2
       public class Complexe {
           public int x;
           public int y;
           public Complexe(){}
           public Complexe(int x, int y)
           {
                this.x=x;
                this.y=y;
           }
           public String toString()
           {
                return x+"+"+y+"i";
           }
           public Complexe Produit(Complexe z1)
           {
                Complexe z =new Complexe( this.x*z1.x-this.y*z1.y ,
       this.x*z1.y+this.y*z1.x );
                return z;
           }
           public static Complexe Produit(Complexe z1,Complexe z2)

E-mail : thecomdevteam@gmail.com
WebSite : www.com-dev.net
Phone : +212618037859| +212662516524                                        Page 2
UNIVERSITE MOHAMED I
       FACULTE DES SCIENCES              Année Universitaire : 2011/ 2012
         DEPARTEMENT DE                  Filières : SMI
         MATHEMATIQUES                   Semestre : 5 (3ème année)
         ET INFORMATIQUE                 Module : POO
              OUJDA


            {
                Complexe z =new Complexe( z2.x*z1.x-z2.y*z1.y ,
       z2.x*z1.y+z2.y*z1.x );
                return z;
           }
           public Complexe Somme(Complexe z1)
           {
                Complexe z =new Complexe( this.x+z1.x , z1.y+this.y);
                return z;
           }
           public static Complexe Somme(Complexe z1,Complexe z2)
           {
                Complexe z =new Complexe( z2.x+z1.x , z1.y+z2.y);
                return z;
           }
       }

Exercice 3
    La Classe personne :
       public class Personne {
       private String nom ;
       private String prenom;
       public Personne(String nom, String prenom) {
           this.nom = nom;
           this.prenom = prenom;
       }
       public String getNom() {
           return nom;
       }
       public void setNom(String nom) {
           this.nom = nom;
       }
       public String getPrenom() {
E-mail : thecomdevteam@gmail.com
WebSite : www.com-dev.net
Phone : +212618037859| +212662516524                                        Page 3
UNIVERSITE MOHAMED I
       FACULTE DES SCIENCES              Année Universitaire : 2011/ 2012
         DEPARTEMENT DE                  Filières : SMI
         MATHEMATIQUES                   Semestre : 5 (3ème année)
         ET INFORMATIQUE                 Module : POO
              OUJDA


            return prenom;
       }
       public void setPrenom(String prenom) {
           this.prenom = prenom;
       }
       public void affiche()
       {
           System.out.println("nom : "+ this.nom+ "nprenom
       :"+this.prenom);
           this.afficheid();
       }
       public void afficheid(){}
       }
    La classe Etudiant :
       public class Etudiant extends Personne{
           private int CNE ;
           public Etudiant(String nom, String prenom, int CNE) {
                super(nom, prenom);
                this.CNE = CNE;
           }
           public void affiche() {
                super.affiche();
                System.out.println("CNE : "+this.CNE);
           }
       }
          La classe Enseignant :
       public class Enseignant extends Personne{
       private int Somme;
       public Enseignant(String nom, String prenom, int Somme) {
       super(nom, prenom);
       this.Somme = Somme;
       }
       public void afficheid() {
       System.out.println("N Somme :"+this.Somme);
E-mail : thecomdevteam@gmail.com
WebSite : www.com-dev.net
Phone : +212618037859| +212662516524                                        Page 4
UNIVERSITE MOHAMED I
       FACULTE DES SCIENCES              Année Universitaire : 2011/ 2012
         DEPARTEMENT DE                  Filières : SMI
         MATHEMATIQUES                   Semestre : 5 (3ème année)
         ET INFORMATIQUE                 Module : POO
              OUJDA


       }
       }

    La classe TestPersonne :
       public class TestPersonne {
           public static void main(String[] args) {
       Personne[] P = new Personne[2];
       P[0]=new Enseignant("COMDEV","TEAM",145921);
       P[1]=new Etudiant("TEAM","COMDEV",45892);
       P[0].affiche();
       P[1].affiche();
           }
       }

Exercice 4
            La classe Point :
       public class Point {
           public int x,y;
           public Point(int x, int y) throws ErrConst{
                if (x<0 || y<0) throw new ErrConst(x,y);
                this.x = x;
                this.y = y;
           }
       }

            La classe ErrConst :
       public class ErrConst extends Exception {
           public ErrConst(int x,int y) {
                System.out.println("Erreur : cordoné négative x= "+x+"
       y = "+y);
           }
       }
E-mail : thecomdevteam@gmail.com
WebSite : www.com-dev.net
Phone : +212618037859| +212662516524                                        Page 5
UNIVERSITE MOHAMED I
       FACULTE DES SCIENCES              Année Universitaire : 2011/ 2012
         DEPARTEMENT DE                  Filières : SMI
         MATHEMATIQUES                   Semestre : 5 (3ème année)
         ET INFORMATIQUE                 Module : POO
              OUJDA


          La classe TestPoint :
       public class TestPoint {
           public static void main(String[] args) {
                try
                {
                     Point p = new Point(1,-22);
                }
                catch (ErrConst e)
                {
                     System.exit(-1);
                }
           }
       }




E-mail : thecomdevteam@gmail.com
WebSite : www.com-dev.net
Phone : +212618037859| +212662516524                                        Page 6

Contenu connexe

Tendances

Travaux dirigés 1: algorithme & structures de données (corrigés)
Travaux dirigés 1: algorithme & structures de données (corrigés)Travaux dirigés 1: algorithme & structures de données (corrigés)
Travaux dirigés 1: algorithme & structures de données (corrigés)
Ines Ouaz
 
GUIDE DE PRÉSENTATION DU STAGE D’INITIATION
GUIDE DE PRÉSENTATION DU STAGE D’INITIATIONGUIDE DE PRÉSENTATION DU STAGE D’INITIATION
GUIDE DE PRÉSENTATION DU STAGE D’INITIATION
Bahae Eddine Halim
 
Rapport de stage (promoteur immobilier )
Rapport de stage (promoteur immobilier )Rapport de stage (promoteur immobilier )
Rapport de stage (promoteur immobilier )
Aicha OUALLA
 
Gestion des Chercheurs d’Emploi
Gestion des Chercheurs d’EmploiGestion des Chercheurs d’Emploi
Gestion des Chercheurs d’Emploi
Azzeddine Elouadi
 
Chapitre 5 classes abstraites et interfaces
Chapitre 5  classes abstraites et interfacesChapitre 5  classes abstraites et interfaces
Chapitre 5 classes abstraites et interfaces
Amir Souissi
 
Marzouk architecture encouches-jee-mvc
Marzouk architecture encouches-jee-mvcMarzouk architecture encouches-jee-mvc
Marzouk architecture encouches-jee-mvc
abderrahim marzouk
 
Présentation du stage echatibi sofian
Présentation du stage echatibi sofianPrésentation du stage echatibi sofian
Présentation du stage echatibi sofian
Sofiane Echatibi
 
Rapport de projet de fin d"études
Rapport de projet de fin d"étudesRapport de projet de fin d"études
Rapport de projet de fin d"études
Mohamed Boubaya
 
rapport PFE ingénieur génie logiciel INSAT
rapport PFE ingénieur génie logiciel INSATrapport PFE ingénieur génie logiciel INSAT
rapport PFE ingénieur génie logiciel INSATSiwar GUEMRI
 
Correction Examen 2016-2017 POO .pdf
Correction Examen 2016-2017 POO .pdfCorrection Examen 2016-2017 POO .pdf
Correction Examen 2016-2017 POO .pdf
slimyaich3
 
Examen 2011 exo 4
Examen 2011 exo 4Examen 2011 exo 4
Examen 2011 exo 4
cheikhany ejiwen
 
Presentation de soutenance du Projet Fin d'Etudes
Presentation de soutenance du Projet Fin d'EtudesPresentation de soutenance du Projet Fin d'Etudes
Presentation de soutenance du Projet Fin d'Etudes
Tahani RIAHI
 
Support POO Java Deuxième Partie
Support POO Java Deuxième PartieSupport POO Java Deuxième Partie
Support POO Java Deuxième Partie
ENSET, Université Hassan II Casablanca
 
Projet de fin d'etude gestion informatique
Projet de fin d'etude gestion informatiqueProjet de fin d'etude gestion informatique
Projet de fin d'etude gestion informatique
jihene Ab
 
Rapport Projet ERP - Plateforme Odoo 12 (PFE Licence)
Rapport Projet ERP - Plateforme Odoo 12 (PFE Licence)Rapport Projet ERP - Plateforme Odoo 12 (PFE Licence)
Rapport Projet ERP - Plateforme Odoo 12 (PFE Licence)
Yasmine Tounsi
 
Rapport pfe
Rapport pfeRapport pfe
Rapport pfe
Ahmed rebai
 
Rapport- Conception et réalisation d'une plateforme social learning
Rapport- Conception et réalisation d'une plateforme social learningRapport- Conception et réalisation d'une plateforme social learning
Rapport- Conception et réalisation d'une plateforme social learning
Rouâa Ben Hammouda
 
Rapport Pfe Application Web e-commerce Symfony2
Rapport Pfe Application Web e-commerce Symfony2Rapport Pfe Application Web e-commerce Symfony2
Rapport Pfe Application Web e-commerce Symfony2
Ben Abdelwahed Slim
 
Présentation de mon PFE
Présentation de mon PFEPrésentation de mon PFE
Présentation de mon PFE
Nadir Haouari
 
Rapport pfe Conceptionet Developpement d'une Application web et Mobile
Rapport pfe Conceptionet Developpement d'une Application web et  Mobile Rapport pfe Conceptionet Developpement d'une Application web et  Mobile
Rapport pfe Conceptionet Developpement d'une Application web et Mobile
Raoua Bennasr
 

Tendances (20)

Travaux dirigés 1: algorithme & structures de données (corrigés)
Travaux dirigés 1: algorithme & structures de données (corrigés)Travaux dirigés 1: algorithme & structures de données (corrigés)
Travaux dirigés 1: algorithme & structures de données (corrigés)
 
GUIDE DE PRÉSENTATION DU STAGE D’INITIATION
GUIDE DE PRÉSENTATION DU STAGE D’INITIATIONGUIDE DE PRÉSENTATION DU STAGE D’INITIATION
GUIDE DE PRÉSENTATION DU STAGE D’INITIATION
 
Rapport de stage (promoteur immobilier )
Rapport de stage (promoteur immobilier )Rapport de stage (promoteur immobilier )
Rapport de stage (promoteur immobilier )
 
Gestion des Chercheurs d’Emploi
Gestion des Chercheurs d’EmploiGestion des Chercheurs d’Emploi
Gestion des Chercheurs d’Emploi
 
Chapitre 5 classes abstraites et interfaces
Chapitre 5  classes abstraites et interfacesChapitre 5  classes abstraites et interfaces
Chapitre 5 classes abstraites et interfaces
 
Marzouk architecture encouches-jee-mvc
Marzouk architecture encouches-jee-mvcMarzouk architecture encouches-jee-mvc
Marzouk architecture encouches-jee-mvc
 
Présentation du stage echatibi sofian
Présentation du stage echatibi sofianPrésentation du stage echatibi sofian
Présentation du stage echatibi sofian
 
Rapport de projet de fin d"études
Rapport de projet de fin d"étudesRapport de projet de fin d"études
Rapport de projet de fin d"études
 
rapport PFE ingénieur génie logiciel INSAT
rapport PFE ingénieur génie logiciel INSATrapport PFE ingénieur génie logiciel INSAT
rapport PFE ingénieur génie logiciel INSAT
 
Correction Examen 2016-2017 POO .pdf
Correction Examen 2016-2017 POO .pdfCorrection Examen 2016-2017 POO .pdf
Correction Examen 2016-2017 POO .pdf
 
Examen 2011 exo 4
Examen 2011 exo 4Examen 2011 exo 4
Examen 2011 exo 4
 
Presentation de soutenance du Projet Fin d'Etudes
Presentation de soutenance du Projet Fin d'EtudesPresentation de soutenance du Projet Fin d'Etudes
Presentation de soutenance du Projet Fin d'Etudes
 
Support POO Java Deuxième Partie
Support POO Java Deuxième PartieSupport POO Java Deuxième Partie
Support POO Java Deuxième Partie
 
Projet de fin d'etude gestion informatique
Projet de fin d'etude gestion informatiqueProjet de fin d'etude gestion informatique
Projet de fin d'etude gestion informatique
 
Rapport Projet ERP - Plateforme Odoo 12 (PFE Licence)
Rapport Projet ERP - Plateforme Odoo 12 (PFE Licence)Rapport Projet ERP - Plateforme Odoo 12 (PFE Licence)
Rapport Projet ERP - Plateforme Odoo 12 (PFE Licence)
 
Rapport pfe
Rapport pfeRapport pfe
Rapport pfe
 
Rapport- Conception et réalisation d'une plateforme social learning
Rapport- Conception et réalisation d'une plateforme social learningRapport- Conception et réalisation d'une plateforme social learning
Rapport- Conception et réalisation d'une plateforme social learning
 
Rapport Pfe Application Web e-commerce Symfony2
Rapport Pfe Application Web e-commerce Symfony2Rapport Pfe Application Web e-commerce Symfony2
Rapport Pfe Application Web e-commerce Symfony2
 
Présentation de mon PFE
Présentation de mon PFEPrésentation de mon PFE
Présentation de mon PFE
 
Rapport pfe Conceptionet Developpement d'une Application web et Mobile
Rapport pfe Conceptionet Developpement d'une Application web et  Mobile Rapport pfe Conceptionet Developpement d'une Application web et  Mobile
Rapport pfe Conceptionet Developpement d'une Application web et Mobile
 

Plus de yassine kchiri

Al2istimta3 bi al3amal
Al2istimta3 bi al3amalAl2istimta3 bi al3amal
Al2istimta3 bi al3amalyassine kchiri
 
Al2istimta3 bi al3amal
Al2istimta3 bi al3amalAl2istimta3 bi al3amal
Al2istimta3 bi al3amal
yassine kchiri
 
Correction bd 2
Correction bd 2Correction bd 2
Correction bd 2
yassine kchiri
 
Cours Base de Données
Cours Base de DonnéesCours Base de Données
Cours Base de Données
yassine kchiri
 
Nachra2011
Nachra2011Nachra2011
Nachra2011
yassine kchiri
 
Cours java smi_2011_2012_partie_i_29_octobre_2011
Cours java smi_2011_2012_partie_i_29_octobre_2011Cours java smi_2011_2012_partie_i_29_octobre_2011
Cours java smi_2011_2012_partie_i_29_octobre_2011yassine kchiri
 
Correction du TD architecture
Correction du TD architectureCorrection du TD architecture
Correction du TD architecture
yassine kchiri
 
Cours des bases de données
Cours des bases de données Cours des bases de données
Cours des bases de données
yassine kchiri
 

Plus de yassine kchiri (13)

Al2istimta3 bi al3amal
Al2istimta3 bi al3amalAl2istimta3 bi al3amal
Al2istimta3 bi al3amal
 
Al2istimta3 bi al3amal
Al2istimta3 bi al3amalAl2istimta3 bi al3amal
Al2istimta3 bi al3amal
 
Correction bd 2
Correction bd 2Correction bd 2
Correction bd 2
 
SQL partie III
SQL partie IIISQL partie III
SQL partie III
 
Cours Base de Données
Cours Base de DonnéesCours Base de Données
Cours Base de Données
 
Serie de TD 3 POO
Serie de TD 3 POOSerie de TD 3 POO
Serie de TD 3 POO
 
Nachra2011
Nachra2011Nachra2011
Nachra2011
 
Correction bd td1
Correction bd td1Correction bd td1
Correction bd td1
 
Cours java smi_2011_2012_partie_i_29_octobre_2011
Cours java smi_2011_2012_partie_i_29_octobre_2011Cours java smi_2011_2012_partie_i_29_octobre_2011
Cours java smi_2011_2012_partie_i_29_octobre_2011
 
Correction du TD architecture
Correction du TD architectureCorrection du TD architecture
Correction du TD architecture
 
Smi5 cours partie2
Smi5 cours partie2Smi5 cours partie2
Smi5 cours partie2
 
Smi5 cours partie1
Smi5 cours partie1Smi5 cours partie1
Smi5 cours partie1
 
Cours des bases de données
Cours des bases de données Cours des bases de données
Cours des bases de données
 

Correction de td poo n3

  • 1. UNIVERSITE MOHAMED I FACULTE DES SCIENCES Année Universitaire : 2011/ 2012 DEPARTEMENT DE Filières : SMI MATHEMATIQUES Semestre : 5 (3ème année) ET INFORMATIQUE Module : POO OUJDA CORRECTION DE LA SERIE 3 DU TD DU POO Exercice 1 Soit le Programme suivant : public class TestPoint { public static void main (String[] args) { int n; n =Clavier.lireInt(); switch(n) { case 0:System.out.println("case 0"); case 1: case 2:System.out.println("case 2"); break; case 3:System.out.println("case 3"); break; case 4: case 5:System.out.println("case 5"); default :System.out.println("Autre"); } } } Le résultat de l’exécution de ce Programme dans le cas ou : n=0 : case 0 case 2 n=1 : case 2 n=2 : case 2 E-mail : thecomdevteam@gmail.com WebSite : www.com-dev.net Phone : +212618037859| +212662516524 Page 1
  • 2. UNIVERSITE MOHAMED I FACULTE DES SCIENCES Année Universitaire : 2011/ 2012 DEPARTEMENT DE Filières : SMI MATHEMATIQUES Semestre : 5 (3ème année) ET INFORMATIQUE Module : POO OUJDA n=3 : case 3 n=4 : case 5 Autre n=10 : Autre n=-5 : Autre Exercice 2 public class Complexe { public int x; public int y; public Complexe(){} public Complexe(int x, int y) { this.x=x; this.y=y; } public String toString() { return x+"+"+y+"i"; } public Complexe Produit(Complexe z1) { Complexe z =new Complexe( this.x*z1.x-this.y*z1.y , this.x*z1.y+this.y*z1.x ); return z; } public static Complexe Produit(Complexe z1,Complexe z2) E-mail : thecomdevteam@gmail.com WebSite : www.com-dev.net Phone : +212618037859| +212662516524 Page 2
  • 3. UNIVERSITE MOHAMED I FACULTE DES SCIENCES Année Universitaire : 2011/ 2012 DEPARTEMENT DE Filières : SMI MATHEMATIQUES Semestre : 5 (3ème année) ET INFORMATIQUE Module : POO OUJDA { Complexe z =new Complexe( z2.x*z1.x-z2.y*z1.y , z2.x*z1.y+z2.y*z1.x ); return z; } public Complexe Somme(Complexe z1) { Complexe z =new Complexe( this.x+z1.x , z1.y+this.y); return z; } public static Complexe Somme(Complexe z1,Complexe z2) { Complexe z =new Complexe( z2.x+z1.x , z1.y+z2.y); return z; } } Exercice 3  La Classe personne : public class Personne { private String nom ; private String prenom; public Personne(String nom, String prenom) { this.nom = nom; this.prenom = prenom; } public String getNom() { return nom; } public void setNom(String nom) { this.nom = nom; } public String getPrenom() { E-mail : thecomdevteam@gmail.com WebSite : www.com-dev.net Phone : +212618037859| +212662516524 Page 3
  • 4. UNIVERSITE MOHAMED I FACULTE DES SCIENCES Année Universitaire : 2011/ 2012 DEPARTEMENT DE Filières : SMI MATHEMATIQUES Semestre : 5 (3ème année) ET INFORMATIQUE Module : POO OUJDA return prenom; } public void setPrenom(String prenom) { this.prenom = prenom; } public void affiche() { System.out.println("nom : "+ this.nom+ "nprenom :"+this.prenom); this.afficheid(); } public void afficheid(){} }  La classe Etudiant : public class Etudiant extends Personne{ private int CNE ; public Etudiant(String nom, String prenom, int CNE) { super(nom, prenom); this.CNE = CNE; } public void affiche() { super.affiche(); System.out.println("CNE : "+this.CNE); } }  La classe Enseignant : public class Enseignant extends Personne{ private int Somme; public Enseignant(String nom, String prenom, int Somme) { super(nom, prenom); this.Somme = Somme; } public void afficheid() { System.out.println("N Somme :"+this.Somme); E-mail : thecomdevteam@gmail.com WebSite : www.com-dev.net Phone : +212618037859| +212662516524 Page 4
  • 5. UNIVERSITE MOHAMED I FACULTE DES SCIENCES Année Universitaire : 2011/ 2012 DEPARTEMENT DE Filières : SMI MATHEMATIQUES Semestre : 5 (3ème année) ET INFORMATIQUE Module : POO OUJDA } }  La classe TestPersonne : public class TestPersonne { public static void main(String[] args) { Personne[] P = new Personne[2]; P[0]=new Enseignant("COMDEV","TEAM",145921); P[1]=new Etudiant("TEAM","COMDEV",45892); P[0].affiche(); P[1].affiche(); } } Exercice 4  La classe Point : public class Point { public int x,y; public Point(int x, int y) throws ErrConst{ if (x<0 || y<0) throw new ErrConst(x,y); this.x = x; this.y = y; } }  La classe ErrConst : public class ErrConst extends Exception { public ErrConst(int x,int y) { System.out.println("Erreur : cordoné négative x= "+x+" y = "+y); } } E-mail : thecomdevteam@gmail.com WebSite : www.com-dev.net Phone : +212618037859| +212662516524 Page 5
  • 6. UNIVERSITE MOHAMED I FACULTE DES SCIENCES Année Universitaire : 2011/ 2012 DEPARTEMENT DE Filières : SMI MATHEMATIQUES Semestre : 5 (3ème année) ET INFORMATIQUE Module : POO OUJDA  La classe TestPoint : public class TestPoint { public static void main(String[] args) { try { Point p = new Point(1,-22); } catch (ErrConst e) { System.exit(-1); } } } E-mail : thecomdevteam@gmail.com WebSite : www.com-dev.net Phone : +212618037859| +212662516524 Page 6