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

PDF
Corrige tp java
Maya Medjdoub
 
PDF
Correction de td poo n2
yassine kchiri
 
PDF
Assembleur
Coulibaly27
 
PDF
Algorithme génétique
Ilhem Daoudi
 
PDF
Cours java
Zakaria Mouammin
 
PDF
IA et éducation
François Guité
 
PDF
Exercices uml-corrige
AmineMouhout1
 
PDF
La spécification des besoins
Ismahen Traya
 
Corrige tp java
Maya Medjdoub
 
Correction de td poo n2
yassine kchiri
 
Assembleur
Coulibaly27
 
Algorithme génétique
Ilhem Daoudi
 
Cours java
Zakaria Mouammin
 
IA et éducation
François Guité
 
Exercices uml-corrige
AmineMouhout1
 
La spécification des besoins
Ismahen Traya
 

Tendances (20)

PPTX
Sécurité de l'IoT | Internet des objets - Formation d'une journée
Tactika inc.
 
PPT
l'Intelligence Artificielle Jean-Antoine Moreau
Jean-Antoine Moreau
 
PDF
Rapport de mon First Projet Web à l'Ecole Supérieure de Technologie de SAFI -...
Mohammed JAITI
 
PPT
Cours des bases de données
yassine kchiri
 
PDF
Systèmes multi agents concepts et mise en oeuvre avec le middleware jade
ENSET, Université Hassan II Casablanca
 
PDF
Intelligence Artificielle - Algorithmes de recherche
Mohamed Heny SELMI
 
PDF
Chapitre 3 NP-complétude
Sana Aroussi
 
PPTX
Présentation PFE
Semah Mhamdi
 
PDF
Intelligence Artificielle : Introduction à l'intelligence artificielle
ECAM Brussels Engineering School
 
PDF
Développement d'un site web jee de e commerce basé sur spring (m.youssfi)
ENSET, Université Hassan II Casablanca
 
PDF
QCM Sécurité Informatique
Zakariyaa AIT ELMOUDEN
 
PDF
Chp5 - Diagramme d'Etat Transition
Lilia Sfaxi
 
PDF
TP C++ : Correction
L’Université Hassan 1er Settat
 
PDF
TP sous linux
ImnaTech
 
PPTX
Intelligence Artificielle et cybersécurité
OPcyberland
 
PDF
Chap1: Cours en C++
Aziz Darouichi
 
PPTX
La détection des spam
Nour El Houda Megherbi
 
PDF
Présentation intelligence artificielle et domaines d'applications - #DigitalT...
Digital Thursday
 
PDF
TD2 - UML - Correction
Lilia Sfaxi
 
PPTX
gestion de magasin vente matériels informatique
Oussama Yoshiki
 
Sécurité de l'IoT | Internet des objets - Formation d'une journée
Tactika inc.
 
l'Intelligence Artificielle Jean-Antoine Moreau
Jean-Antoine Moreau
 
Rapport de mon First Projet Web à l'Ecole Supérieure de Technologie de SAFI -...
Mohammed JAITI
 
Cours des bases de données
yassine kchiri
 
Systèmes multi agents concepts et mise en oeuvre avec le middleware jade
ENSET, Université Hassan II Casablanca
 
Intelligence Artificielle - Algorithmes de recherche
Mohamed Heny SELMI
 
Chapitre 3 NP-complétude
Sana Aroussi
 
Présentation PFE
Semah Mhamdi
 
Intelligence Artificielle : Introduction à l'intelligence artificielle
ECAM Brussels Engineering School
 
Développement d'un site web jee de e commerce basé sur spring (m.youssfi)
ENSET, Université Hassan II Casablanca
 
QCM Sécurité Informatique
Zakariyaa AIT ELMOUDEN
 
Chp5 - Diagramme d'Etat Transition
Lilia Sfaxi
 
TP sous linux
ImnaTech
 
Intelligence Artificielle et cybersécurité
OPcyberland
 
Chap1: Cours en C++
Aziz Darouichi
 
La détection des spam
Nour El Houda Megherbi
 
Présentation intelligence artificielle et domaines d'applications - #DigitalT...
Digital Thursday
 
TD2 - UML - Correction
Lilia Sfaxi
 
gestion de magasin vente matériels informatique
Oussama Yoshiki
 
Publicité

Plus de yassine kchiri (12)

PDF
Al2istimta3 bi al3amal
yassine kchiri
 
PPTX
Al2istimta3 bi al3amal
yassine kchiri
 
PDF
Correction bd 2
yassine kchiri
 
PDF
SQL partie III
yassine kchiri
 
PDF
Cours Base de Données
yassine kchiri
 
PDF
Serie de TD 3 POO
yassine kchiri
 
PDF
Nachra2011
yassine kchiri
 
PDF
Correction bd td1
yassine kchiri
 
PDF
Cours java smi_2011_2012_partie_i_29_octobre_2011
yassine kchiri
 
PDF
Correction du TD architecture
yassine kchiri
 
PDF
Smi5 cours partie2
yassine kchiri
 
PDF
Smi5 cours partie1
yassine kchiri
 
Al2istimta3 bi al3amal
yassine kchiri
 
Al2istimta3 bi al3amal
yassine kchiri
 
Correction bd 2
yassine kchiri
 
SQL partie III
yassine kchiri
 
Cours Base de Données
yassine kchiri
 
Serie de TD 3 POO
yassine kchiri
 
Nachra2011
yassine kchiri
 
Correction bd td1
yassine kchiri
 
Cours java smi_2011_2012_partie_i_29_octobre_2011
yassine kchiri
 
Correction du TD architecture
yassine kchiri
 
Smi5 cours partie2
yassine kchiri
 
Smi5 cours partie1
yassine kchiri
 
Publicité

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 : [email protected] 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 : [email protected] 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 : [email protected] 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 : [email protected] 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 : [email protected] 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 : [email protected] WebSite : www.com-dev.net Phone : +212618037859| +212662516524 Page 6