Public Class Livre { protected static final String TITRE_DEFAUT = " La terre "; protected static final String AUTEUR_DEFAUT = " Paul "; protected static final int PRIX_DEFAUT = 10; protected String titre; protected String auteur; protected float prix; protected int annee; Public Livre() { this.titre = TITRE_DEFAUT; this.auteur = AUTEUR_DEFAUT; this.prix = PRIX_DEFAUT; System.out.println("Création d'un livre"); } Public Livre (String titre) { this(); this.titre = titre; } Public Livre (String titre, String auteur) { this(titre); this.auteur = auteur; } Public Livre (String titre, String auteur, int prix) { this(titre, auteur); this.prix = prix; } public String getTitre() { return this.titre; } public void setTitre(String titre) { this.titre = titre; } public String getAuteur() { return this.auteur; } public void setAuteur(String auteur) { this.auteur = auteur; } public String getPrix() { return this.prix; } public void setPrix(int prix) { this.prix = prix; } }
public Livre(String titre) { this.titre = titre; }
public static void main(String[] args) { Livre livre = new Livre(" La Terre "); }
public class Livre { private String titre; private String auteur; private float prix; private int annee; public Livre() { } public Livre(String livre, String auteur) { this.titre = livre; this.auteur = auteur; } public Livre(String titre, String auteur, float prix) { this.titre = titre; this.auteur = auteur; this.prix = prix; } public Livre(String titre, String auteur, float prix, int annee) { this.titre = titre; this.auteur = auteur; this.prix = prix; this.annee = annee; } public String getLivre() { return titre; } public void setLivre(String livre) { this.titre = livre; } public String getAuteur() { return auteur; } public void setAuteur(String auteur) { this.auteur = auteur; } public float getPrix() { return prix; } public void setPrix(float prix) { this.prix = prix; } public int getAnnee() { return annee; } public void setAnnee(int annee) { this.annee = annee; } }
public class ProgPrincipal { public static void main(String[] args) { Livre l1 = new Livre(); Livre l2 = new Livre("la terre", "Paul"); ... } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question