Commit e54b63c8 authored by bonnabab's avatar bonnabab
Browse files

tp4 maj

parent ad1bd7b0
No preview for this file type
public class Aigle extends Carnivore{
public class Aigle extends Animal{
static final double QTEDEFAUTJOUR=1;
private int envergure;
public Aigle(String nom, double poids, int envergure){
super(nom,poids,QTEDEFAUTJOUR);
super(nom,poids,new Viande(QTEDEFAUTJOUR));
this.envergure=envergure;
}
public Aigle(String nom, double poids, int envergure, double qteparjour){
super(nom,poids,qteparjour);
super(nom,poids,new Viande(QTEDEFAUTJOUR));
this.envergure=envergure;
}
......
No preview for this file type
public abstract class Animal{
private String nom;
private double poids;
private Regime regime;
public Animal(String nom,double p){
public Animal(String nom,double p, Regime r){
this.nom=nom;
this.poids=p;
this.regime=r;
}
public String getNom(){
......@@ -12,7 +14,18 @@ public abstract class Animal{
}
public abstract String getCri();
public abstract double getCout();
public double getCout(){
return regime.getCout();
}
public Regime getRegime(){
return regime;
}
public void modifyRegime(double qte){
regime.modifyQte(qte);
}
public boolean equals(Object obj){
if (obj instanceof Animal){
......
No preview for this file type
public class Autruche extends Vegetarien{
public class Autruche extends Animal{
private int nbPlumes;
static final int QTEJOUR=5;
public Autruche(String nom, double poids, int nbPlumes){
super(nom,poids,QTEJOUR);
super(nom,poids,new Legume(QTEJOUR));
this.nbPlumes=nbPlumes;
}
......
No preview for this file type
public abstract class Carnivore extends Animal{
double quantiteViande;
protected double quantiteViande;
public Carnivore(String nom, double poids,double quantiteViande){
super(nom,poids);
......
No preview for this file type
public class Chimpanze extends Vegetarien{
public class Chimpanze extends Animal{
static final int QTEJOUR=3;
public Chimpanze(String nom, double poids){
super(nom,poids,QTEJOUR);
super(nom,poids,new Legume(QTEJOUR));
}
@Override
......
import java.math.*;
public class Legume extends Regime{;
public Legume(double qte){
super(qte);
}
@Override
public double getCout(){
return 1.2*Math.log((super.getqte()+5)*2+1);
}
}
No preview for this file type
public class Orque extends Carnivore{
public class Orque extends Animal{
static final double QTEJOUR_PAR_KG=0.1;
public Orque(String nom, double poids){
super(nom,poids,QTEJOUR_PAR_KG*poids);
super(nom,poids,new Viande(QTEJOUR_PAR_KG*poids));
}
public void setPoids(double p){
super.setPoids(p);
this.quantiteViande=p*QTEJOUR_PAR_KG;
super.modifyRegime(p*QTEJOUR_PAR_KG);
}
@Override
......
public abstract class Regime{
private double qte;
public Regime(double qte){
this.qte=qte;
}
public abstract double getCout();
public double getqte(){
return qte;
}
public void modifyQte(double qte){
this.qte=qte;
}
}
No preview for this file type
No preview for this file type
public class TigreBengale extends Carnivore{
public class TigreBengale extends Animal{
static final int QTEJOUR=4;
private int nbRayures;
public TigreBengale(String nom, double poids, int nbRayures){
super(nom,poids,QTEJOUR);
super(nom,poids,new Viande(QTEJOUR));
this.nbRayures=nbRayures;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment