80 lines
2.3 KiB
Java
80 lines
2.3 KiB
Java
|
public class Confiture {
|
|||
|
|
|||
|
// Attributs
|
|||
|
private String cuisinier, parfum;
|
|||
|
private int annee;
|
|||
|
private int id;
|
|||
|
private static int c_nextId=1;
|
|||
|
|
|||
|
|
|||
|
// Constructeur
|
|||
|
public Confiture ( String parfum, String cuisinier,int an ) {
|
|||
|
this.parfum = parfum;
|
|||
|
this.cuisinier = cuisinier;
|
|||
|
this.annee = an;
|
|||
|
this.id=c_nextId++;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
// Accesseurs
|
|||
|
public String getCuisinier() {
|
|||
|
return this.cuisinier;
|
|||
|
}
|
|||
|
|
|||
|
public String getParfum() {
|
|||
|
return this.parfum;
|
|||
|
}
|
|||
|
|
|||
|
public int getAnnee() {
|
|||
|
return this.annee;
|
|||
|
}
|
|||
|
|
|||
|
// Modificateurs
|
|||
|
public void setAnnee( int annee ) {
|
|||
|
if ( annee >= 0 )
|
|||
|
this.annee = annee;
|
|||
|
else
|
|||
|
System.err.println( "Attention ! l'ann<6E>e entr<74>e n'est pas valide" );
|
|||
|
}
|
|||
|
|
|||
|
public void setCuisinier( String cuisinier ) {
|
|||
|
this.cuisinier = cuisinier;
|
|||
|
}
|
|||
|
|
|||
|
public void setParfum( String parfum ) {
|
|||
|
this.parfum = parfum;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
// M<>thode d'affichage
|
|||
|
public String toString() {
|
|||
|
StringBuffer infos = new StringBuffer(" ");
|
|||
|
infos.append(this.id);
|
|||
|
infos.append(" : Confiture de ").append(this.parfum);
|
|||
|
infos.append(" par ").append(this.cuisinier);
|
|||
|
infos.append(" (").append(this.annee).append(")");
|
|||
|
String res=new String(infos);
|
|||
|
return res;
|
|||
|
}
|
|||
|
|
|||
|
public static void main( String args[] ) {
|
|||
|
|
|||
|
// Creation des deux confitures
|
|||
|
Confiture conf1 = new Confiture("fraise","Maman",2007 );
|
|||
|
Confiture conf2 = new Confiture("framboise","Moi",2006 );
|
|||
|
Confiture conf3 = new Confiture("cassis","Meme",2003 );
|
|||
|
|
|||
|
// Modification d'une ann<6E>e
|
|||
|
conf2.setAnnee( 2005 );
|
|||
|
|
|||
|
// Affichage des cuisiniers
|
|||
|
System.out.println( "Cuisinier confiture 1 : " + conf1.getCuisinier() );
|
|||
|
System.out.println( "Cuisinier confiture 2 : " + conf2.getCuisinier() );
|
|||
|
|
|||
|
// Affichage des informations sur la confiture par la m<>thode println
|
|||
|
System.out.println( conf1 );
|
|||
|
System.out.println( conf2 );
|
|||
|
System.out.println( conf3 );
|
|||
|
}
|
|||
|
}
|