Created
January 27, 2019 11:25
-
-
Save m-242/2e25babac0d6376f5dfab23053a161f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Etudiant{ | |
public static String nom, prenom; | |
public static int num; | |
public static int note; | |
public Etudiant(String n, String p, int ne, int no){ | |
nom = n; | |
prenom = p; | |
num = ne; | |
note = no; | |
} | |
public static void afficher(Etudiant etu){ | |
System.out.println("Nom :" | |
+ nom | |
+ " Prénom " | |
+ prenom | |
+ " (" + num + ") " | |
+ " : Note " | |
+ note); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
22/01/2019 | |
TP1 IP2 | |
*/ | |
public class Fruit{ | |
public String nom; | |
public int poids; | |
public Fruit(String n, int p){ | |
nom = n; | |
poids = p; | |
} | |
public static void afficherFruit(Fruit f){ | |
System.out.print("Ce fruit est un(e) "); | |
System.out.print(f.nom); | |
System.out.print(" et pèse "); | |
System.out.print(f.poids); | |
System.out.println(" grammes."); | |
} | |
static Fruit hybridation(Fruit f1, Fruit f2){ | |
String n ="(" + f1.nom + f2.nom + ")"; | |
int p = f1.poids + f2.poids; | |
return new Fruit(n, p); | |
} | |
} | |
/* Q2 | |
-> les variables f et g pointent vers des objets fruits. | |
-> h pointe vers le même objet que f. | |
*/ | |
/* Q3 | |
->Exactement ça | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Panier{ | |
public Fruit[] panierDeFruits; | |
public Panier(Fruit[] f){ | |
this.panierDeFruits = f; | |
} | |
public Panier(){ | |
this.panierDeFruits = new Fruit[0]; | |
} | |
public Panier(Fruit f, Panier p){ | |
this.panierDeFruits = new Fruit[p.panierDeFruits.length+1]; | |
for(int i = 0; i<p.panierDeFruits.length; i++){ | |
this.panierDeFruits[i] = p.panierDeFruits[i]; | |
} | |
this.panierDeFruits[this.panierDeFruits.length-1] = f; | |
} | |
public static void afficher(Panier p){ | |
for(Fruit fruit: p.panierDeFruits){ | |
Fruit.afficherFruit(fruit); | |
} | |
} | |
public static Panier hybridePanier(Fruit f, Panier p){ | |
Fruit[] panierHybride = new Fruit[p.panierDeFruits.length]; | |
for(int i = 0; i < p.panierDeFruits.length; i++){ | |
panierHybride[i] = Fruit.hybridation(f, p.panierDeFruits[i]); | |
} | |
return new Panier(panierHybride); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Test extends Fruit{ | |
public Test(String n, int p){ | |
super(n, p); | |
} | |
public static void main(String[] args){ | |
Fruit f = new Fruit("pamplemousse", 330); | |
Fruit g = new Fruit("orange", 330); | |
Fruit h = Fruit.hybridation(f, g); | |
Fruit.afficherFruit(h); | |
System.out.println("Test terminé"); | |
//panier | |
// Panier vide | |
Panier a = new Panier(); | |
// Panier plein | |
Fruit f1 = new Fruit("aa", 44); | |
Fruit[] p1 = new Fruit[]{f1}; | |
Panier b = new Panier(p1); | |
// Ajout fruit dans panier | |
//on réutilise b | |
Fruit f2 = new Fruit("vv", 54); | |
Panier c = new Panier(f2, b); | |
// Panier Hybride | |
Panier d = Panier.hybridePanier(f, c); | |
Panier.afficher(d); | |
} | |
} | |
/* | |
Q4: | |
Il faut faire hériter la classe Test de la classe Fruit | |
et créer un constructeur dans Test appelant le CTOR de | |
Fruit. | |
*/ | |
/* | |
Q6: | |
On appelle une méthode de la classe mère avec Mère.{nom_méthode}(arguments); | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestEtudiant{ | |
public static boolean estAdmis(Etudiant etu){ | |
return (etu.note > 10); | |
} | |
public static String mention(Etudiant etu){ | |
if(etu.note < 0 || etu.note > 20){ | |
return "Note invalide"; | |
} | |
if(etu.note <= 10){ | |
return "Ajourné"; | |
} | |
if(etu.note <= 12){ | |
return "Passable"; | |
} | |
if(etu.note <= 14){ | |
return "Assez bien"; | |
} | |
if(etu.note <= 16){ | |
return "Bien"; | |
} | |
return "Très bien"; | |
} | |
public static void main(String[] args){ | |
Etudiant e1 = new Etudiant("Jean", "Jacques", 152451, 17); | |
System.out.println(mention(e1)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment