SlideShare uma empresa Scribd logo
1 de 6
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

La gestion des exceptions avec Java
La gestion des exceptions avec JavaLa gestion des exceptions avec Java
La gestion des exceptions avec Java
 
Exercice 2 java Héritage
Exercice 2  java HéritageExercice 2  java Héritage
Exercice 2 java Héritage
 
Arbre et algorithme de recherche
Arbre et algorithme de rechercheArbre et algorithme de recherche
Arbre et algorithme de recherche
 
Chapitre 5 classes abstraites et interfaces
Chapitre 5  classes abstraites et interfacesChapitre 5  classes abstraites et interfaces
Chapitre 5 classes abstraites et interfaces
 
POO Java Chapitre 4 Heritage et Polymorphisme
POO Java Chapitre 4 Heritage et PolymorphismePOO Java Chapitre 4 Heritage et Polymorphisme
POO Java Chapitre 4 Heritage et Polymorphisme
 
Support POO Java première partie
Support POO Java première partieSupport POO Java première partie
Support POO Java première partie
 
Java cours n° 2 - classe-objet-constructeur
Java   cours n° 2 - classe-objet-constructeurJava   cours n° 2 - classe-objet-constructeur
Java cours n° 2 - classe-objet-constructeur
 
Cours design pattern m youssfi partie 4 composite
Cours design pattern m youssfi partie 4 compositeCours design pattern m youssfi partie 4 composite
Cours design pattern m youssfi partie 4 composite
 
Chapitre5: Classes et objets
Chapitre5: Classes et objetsChapitre5: Classes et objets
Chapitre5: Classes et objets
 
Chap 6 : classes et interfaces
Chap 6 : classes et interfacesChap 6 : classes et interfaces
Chap 6 : classes et interfaces
 
Programmation orientée objet : Object, classe et encapsulation
Programmation orientée objet : Object, classe et encapsulationProgrammation orientée objet : Object, classe et encapsulation
Programmation orientée objet : Object, classe et encapsulation
 
Chp6 - De UML vers C++
Chp6 - De UML vers C++Chp6 - De UML vers C++
Chp6 - De UML vers C++
 
Java
JavaJava
Java
 
TP C++ : Correction
TP C++ : CorrectionTP C++ : Correction
TP C++ : Correction
 
Support de cours technologie et application m.youssfi
Support de cours technologie et application m.youssfiSupport de cours technologie et application m.youssfi
Support de cours technologie et application m.youssfi
 
Cours design pattern m youssfi partie 1 introduction et pattern strategy
Cours design pattern m youssfi partie 1 introduction et pattern strategyCours design pattern m youssfi partie 1 introduction et pattern strategy
Cours design pattern m youssfi partie 1 introduction et pattern strategy
 
Chap1: Cours en C++
Chap1: Cours en C++Chap1: Cours en C++
Chap1: Cours en C++
 
Android - Tp3 - intents
Android - Tp3 -  intentsAndroid - Tp3 -  intents
Android - Tp3 - intents
 
Rapport de mini projet java
Rapport de mini projet javaRapport de mini projet java
Rapport de mini projet java
 
présentation ppt du stage technicien
présentation ppt du stage technicienprésentation ppt du stage technicien
présentation ppt du stage technicien
 

Mais 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