‏إظهار الرسائل ذات التسميات لغة الجافا. إظهار كافة الرسائل
‏إظهار الرسائل ذات التسميات لغة الجافا. إظهار كافة الرسائل

الخميس، 4 أكتوبر 2018

حل تمرين في الجافا الكائنية - Corréction Exercice Java Héritage POO


حل تمرين في الجافا الكائنية

public class Employe {

 private String nom;
 private int age;
 private float salaire;

 /*Constructeur par défaut*/

 public Employe() {}

 /*Constructeur avec 3 paramètres*/

 public Employe(String nom, int age, float salaire) {
  this.nom = nom;
  this.age = age;
  this.salaire = salaire;
 }

 /*constructeur par copie*/

 public Employe(Employe oldEmploye) {
  nom = oldEmploye.nom;
  age = oldEmploye.age;
  salaire = oldEmploye.salaire;
 }

 /*mutateurs (modificateurs) */

 public void setNom(String nom) {
  this.nom = nom;
 }



 public void setAge(int age) {
  this.age = age;
 }

 public void setSalaire(float salaire) {
  this.salaire = salaire;
 }

 /*accesseurs  (recupérateurs) */

 public String getNom() {
  return (this.nom);
 }

 public int getAge() {
  return (this.age);
 }

 public float getSalaire() {
  return (this.salaire);
 }

 /*toString*/

 public String toString() {
  return nom + "\t" + age + "\t" + salaire;
 }


 public void afficher() {
  System.out.println(toString());
 }

 public void augmentation(float a) {
  salaire = salaire + a;

 }

public class Technicien extends Employe {

 private byte grade;

 public Technicien(String nom, int age, float salaire, byte grade) {
  super(nom, age, salaire);
  this.grade = grade;
 }

 public int prime() {

  switch (grade) {
   case 1:
    return 100;
   case 2:
    return 200;
   case 3:
    return 300;
  }
  return 0;

 }

 public float calculSalaire() {
  return getSalaire() + prime();
 }

 public String toString() {

  return super.toString() + "\t" + grade;
 }

}

class TestEmpTech {
 public static void main(String args[]) {
  Employe e1 = new Employe("Albert", 28, 4500);
  Employe e2 = new Technicien("Bernard", 50, 8000, (byte) 5);

  //Technicien e3 =new Employe();  //erreur

  Technicien e3 = new Technicien("Jacques", 25, 5000, (byte) 4);

  System.out.println("Avant augmentation:");
  e1.afficher();
  e2.afficher();
  e3.afficher();

  e1.augmentation(600);
  e2.augmentation(500);
  e3.augmentation(650);

  System.out.println("Apres augmentation:");
  e1.afficher();
  e2.afficher();
  e3.afficher();


 }
}

تمرين في لغة الجافا الكائنية - Exercice Java Héritage POO

تمرين مع الحل في لغة الجافا الكائنية - Exercice Java Héritage POO

Dans une société, un employé est décrit par les membres suivants :

Attributs : 
Nom,
Age,
salaire.

Constructeurs : 
par défaut,
par copie,
avec trois paramètres.

Méthodes :
Augmentation(…),
toString(),
afficher(),
calculeSalaire().

Un technicien est décrit en plus par l’attribut : grade et la méthode prime( ) et la redéfinition de la méthode toString() et de la méthode calculeSalaire().

Si grade=1 alors Prime= 100
Si grade=2 alors Prime= 200
Si grade=3 alors Prime= 300

Travail à faire :

-Ecrire la classe Employé.
-Ecrire la classe Technicien.
-Ecrire un programme qui saisie un employé puis un technicien et affiche leurs informations avant et après augmentation de leurs salaires.