LaDissertation.com - Dissertations, fiches de lectures, exemples du BAC
Recherche

Exercice Programmation objet Les Classes

TD : Exercice Programmation objet Les Classes. Recherche parmi 298 000+ dissertations

Par   •  21 Avril 2020  •  TD  •  928 Mots (4 Pages)  •  505 Vues

Page 1 sur 4

Programation objet en java

créer une classe personne avec en privée l’identifiant, le nom et le prenom de la personne, avec tout les fonctions et procédures obligatoires.

CORRIGE

Public class Personne {

        private int id;

        private String nom;

        private String prenom;

        public personne(String nom, String prenom, int id)

        {

                this.id = id;

                this.nom = nom;

                this.prenom = prenom;

        }

        public int getId()

        {

                return(this.id);

        }

        public String getNom(){

                return(this.nom);

        }

        public String getPrenom(){

                return(this.prenom);

        }

        public void setId(){

                this.id = id;

        }

        public void setNom(){

                this.nom = nom;

        }

        public void setPrenom(){

                this.prenom = prenom;

        }

        public String(){

                return("La personne à pour nom:" + this.nom + " et à pour prénom: " + this.prenom + ", sont identifiant est: " + this.id)

        }

}

Créer la classe main pour tester l’algorithme

CORRIGE

public class main{

        public static void main(String[] args) {

                Personne unePersonne;

                int id;

                String nom;

                String prenom;

                System.out.println("Veuillez saissir l'identifiant de la personne");

                Scanner sc = new Scanner(System.in);

                id = sc.nextLine();

                System.out.println("Veuillez saissir le nom de la personne");

                nom = sc.nextLine();

                System.out.println("Veuillez saissir le prenom de la personne");

                prenom = sc.nextLine();

                unePersonne = new Personne(id, nom, prenom);

                unePersonne.toString();

                System.out.println("Veuillez saissir l'identifiant de la personne");

                id = sc.nextLine();

                unePersonne.setId(id);

                System.out.println("L'identifiant de la personne est: " + unePersonne.getId());

                System.out.println("Veuillez saissir le nom de la personne");

...

Télécharger au format  txt (2.7 Kb)   pdf (34.6 Kb)   docx (7.1 Kb)  
Voir 3 pages de plus »
Uniquement disponible sur LaDissertation.com