SlideShare une entreprise Scribd logo
1  sur  6
Télécharger pour lire hors ligne
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

Fonctions chaine
Fonctions chaineFonctions chaine
Fonctions chaine
Afef Ilahi
 

Tendances (20)

Tp word n°5
Tp word n°5Tp word n°5
Tp word n°5
 
Fonctions chaine
Fonctions chaineFonctions chaine
Fonctions chaine
 
Rapport mini-projet Gestion Commerciale D’un Supermarché
Rapport mini-projet  Gestion Commerciale D’un SupermarchéRapport mini-projet  Gestion Commerciale D’un Supermarché
Rapport mini-projet Gestion Commerciale D’un Supermarché
 
Telecharger Exercices corrigés PL/SQL
Telecharger Exercices corrigés PL/SQLTelecharger Exercices corrigés PL/SQL
Telecharger Exercices corrigés PL/SQL
 
Rapport projet: relisation d'une app desktop
Rapport projet: relisation d'une app desktop Rapport projet: relisation d'une app desktop
Rapport projet: relisation d'une app desktop
 
Rapport de Stage
Rapport de StageRapport de Stage
Rapport de Stage
 
isa serveur
isa serveurisa serveur
isa serveur
 
Excel ppt.ppt
Excel ppt.pptExcel ppt.ppt
Excel ppt.ppt
 
Les listes simplement chaînées en langage C
Les listes simplement chaînées en langage CLes listes simplement chaînées en langage C
Les listes simplement chaînées en langage C
 
Cours : les listes chainées Prof. KHALIFA MANSOURI
Cours : les listes chainées  Prof. KHALIFA MANSOURI Cours : les listes chainées  Prof. KHALIFA MANSOURI
Cours : les listes chainées Prof. KHALIFA MANSOURI
 
Programmation Java
Programmation JavaProgrammation Java
Programmation Java
 
POO Java Chapitre 2 Encapsulation
POO Java Chapitre 2 EncapsulationPOO Java Chapitre 2 Encapsulation
POO Java Chapitre 2 Encapsulation
 
resume algo 2023.pdf
resume algo 2023.pdfresume algo 2023.pdf
resume algo 2023.pdf
 
Tp word n°3
Tp word n°3Tp word n°3
Tp word n°3
 
Chapitre 5 classes abstraites et interfaces
Chapitre 5  classes abstraites et interfacesChapitre 5  classes abstraites et interfaces
Chapitre 5 classes abstraites et interfaces
 
Exercice 1 java Héritage
Exercice 1 java HéritageExercice 1 java Héritage
Exercice 1 java Héritage
 
Chapitre 3 elements de base de java
Chapitre 3  elements de base de javaChapitre 3  elements de base de java
Chapitre 3 elements de base de java
 
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
 
POO
POOPOO
POO
 
c# programmation orientée objet (Classe & Objet)
c# programmation orientée objet (Classe & Objet)c# programmation orientée objet (Classe & Objet)
c# programmation orientée objet (Classe & Objet)
 

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