1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
public abstract class Nains {
private String nom, pied;
public Nains() {
this("","");
}
public Nains(String nom, String pied) {
this.nom = nom;
this. pied = pied;
}
public String getNom(){
return nom;
}
public void setNom(String nom){
this.nom = nom;
}
public String getPied() {
return pied;
}
public void setPied(String pied) {
this. pied = pied;
}
public String toString(){
return ("Nom : " + nom + "\nPied : " + pied );
}
}
2 classes derivees de Nains :
public class Barbu extends Nains{
public Barbu () {
super();
}
public Barbu(String nom, String pied){
super(nom,pied);
}
public String toString() {
String s = super.toString();
return s ;
}
}
public class Rase2Pres extends Fleurs implements Comparable{
private Date dateRase;
public Rase2Pres () {
super();
dateRase = null;
}
public Rase2Pres (String nom, String pied, Date dateRase){
super(nom,pied);
this.dateRase = dateRase;
}
public String getDateRase() {
return dateRase;
}
public void setDateRase(Date dateRase) {
this.dateRase = dateRase;
}
public int compareTo(Object o) {
return this.dateRase.compareTo( ((Nains)o).dateRase );
}
public String toString() {
String s = super.toString();
return s + "\nDate rasage : " + dateRase;
}
}
public class RaseS2Pres {
private ArrayList a = new ArrayList();
public void add (Rase2Pres f) {
a.add(f);
}
public String toString(){
Collections.sort(a);
String s = "";
for (Object o : a) {
s = s + o + "\n\n";
}
return s;
}
}
public class Test {
public static void main(String args[]) {
Date d1 = new Date(2009,3,15);
Date d2 = new Date(2009,4,01);
Nains f = new Nains();
f.add(new rase2Pres("Le grincheux", "plat", d1));
f.add(new rase2Pres("Le timbré", "grand", d2));
--> pour la fee c 'est la m^me choses et ca donnerai
Fees ar = new Fees();
ar.add(new Fee("Carrabosse",d1));
ar.add(new Fee("Perchee",d2));
}
} |
Partager