diff --git a/2A/S4/Archi_Logiciel/td/exercices/ex3.mjs b/2A/S4/Archi_Logiciel/td/exercices/ex3.mjs index a71408040e7f6f085831466657715d35681fdd93..7ba8abf7b9f8a287b41f96c6e68f6cca4e8ecd80 100644 --- a/2A/S4/Archi_Logiciel/td/exercices/ex3.mjs +++ b/2A/S4/Archi_Logiciel/td/exercices/ex3.mjs @@ -9,7 +9,7 @@ Animal.prototype.crie = function() { const Chien = function(nom) { // on appelle un autre constructeur pour initialiser this - Animal.call(nom); + Animal.call(this,nom); } Chien.prototype = Object.create(Animal.prototype); @@ -19,7 +19,9 @@ Chien.prototype.crie = function() { return Animal.prototype.crie.call(this) + ' wawa' } -console.log(Animal) -console.log(Chien) -console.log(Chien.prototype.crie.call("aaa")) \ No newline at end of file +let animalTest = new Animal("Miauoiuyhg") +let chienTest = new Chien("SSSSSSSSSSSSSSA") + +console.log(animalTest.crie()) +console.log(chienTest.crie()) \ No newline at end of file diff --git a/2A/S4/Archi_Logiciel/td/exercices/ex4_Etudiant.mjs b/2A/S4/Archi_Logiciel/td/exercices/ex4_Etudiant.mjs new file mode 100644 index 0000000000000000000000000000000000000000..45e8ade72ad2894dd2ab703f073cc8f5ae13da58 --- /dev/null +++ b/2A/S4/Archi_Logiciel/td/exercices/ex4_Etudiant.mjs @@ -0,0 +1,25 @@ +"use strict" + +import Humain from "./ex4_Humain.mjs"; + +class Etudiant extends Humain { + note + + constructor(nom, note) { + super(nom); + this.note = note; + } + + toString () { + return "Etudiant nommé " + this.nom + ". Note : " + this.note + } +} + + + +export default Etudiant + +const etu1 = new Etudiant("Test1", 12) +const etu2 = new Etudiant("Test2", 20) +console.log(etu1.toString()) // pour que le toString soit bien utilisé +console.log(etu2.toString()) diff --git a/2A/S4/Archi_Logiciel/td/exercices/ex4_Humain.mjs b/2A/S4/Archi_Logiciel/td/exercices/ex4_Humain.mjs new file mode 100644 index 0000000000000000000000000000000000000000..104af5019f34b4d3abfeb2757caa109b525c0090 --- /dev/null +++ b/2A/S4/Archi_Logiciel/td/exercices/ex4_Humain.mjs @@ -0,0 +1,30 @@ +"use strict" + +class Humain { + // on met nom en private pour ne pas qu'il soit modifiable + // on peut le consulter avec getNom + #nom + static nbInstances = 0 + + constructor(nom) { + this.#nom = nom; + Humain.nbInstances++ + } + + get nom(){ + return this.#nom + } + + toString () { + return "Humain " + this.nom + } +} + + +const moi = new Humain("moi") +const pasMoi = new Humain("pasmoi") + +console.log(moi.nom) +console.log(Humain.nbInstances) + +export default Humain diff --git a/2A/S4/Archi_Logiciel/td/exercices/ex4_Promo.mjs b/2A/S4/Archi_Logiciel/td/exercices/ex4_Promo.mjs new file mode 100644 index 0000000000000000000000000000000000000000..4f6436fc91cf55254c0c39c0db668fa21b834c1a --- /dev/null +++ b/2A/S4/Archi_Logiciel/td/exercices/ex4_Promo.mjs @@ -0,0 +1,58 @@ +"use strict" + +//import Etudiant from "./ex4_Etudiant.mjs"; + +import Etudiant from "./ex4_Etudiant.mjs"; + +class Promotion { + etudiants + constructor() { + this.etudiants = [] + } + + + toString () { + return this.etudiants + } + + addEtu(etu) { + if (!(etu instanceof Etudiant)){ + throw new Error("Ce n'est pas un étudiant") + } + else if (this.etudiants.includes(etu)){ + throw new Error("Etudiant deja présent dans la liste") + } + else{ + this.etudiants.push(etu) + } + } + + +} + +const Promo = new Promotion(); +const etu1 = new Etudiant("Test1", 12) +const etu2 = new Etudiant("Test2", 20) +const etu3 = new Etudiant("Test3", 9) +Promo.addEtu(etu1) +Promo.addEtu(etu2) +Promo.addEtu(etu3) + +console.log(Promo.etudiants) + + + +// CALCUL MOYENNE +const tab= [10,9,20,8,12] +function augmenterPromo(tab,increment){ + tab.map((note)=>(note+increment>=20?note=20:note+=increment)) +} +augmenterPromo(tab,9) +console.log(tab) + +function moyenne(tab){ + var sum = tab.reduce((total, currentNote) => total + currentNote,0) + return sum/tab.length +} + +console.log(moyenne(tab)) \ No newline at end of file