Commit ad1bd7b0 authored by Benjamin Bonnabaud's avatar Benjamin Bonnabaud
Browse files

zoo

parent d0ed4721
File added
public class Aigle extends Carnivore{
static final double QTEDEFAUTJOUR=1;
private int envergure;
public Aigle(String nom, double poids, int envergure){
super(nom,poids,QTEDEFAUTJOUR);
this.envergure=envergure;
}
public Aigle(String nom, double poids, int envergure, double qteparjour){
super(nom,poids,qteparjour);
this.envergure=envergure;
}
public int getEnvergure(){
return envergure;
}
@Override
public String getCri(){
return "Sifflement";
}
@Override
public String toString(){
return "Aigle : "+super.toString()+"; envergure : "+envergure+"; Cri : "+getCri();
}
}
No preview for this file type
......@@ -4,7 +4,7 @@ public abstract class Animal{
public Animal(String nom,double p){
this.nom=nom;
this.poids=poids;
this.poids=p;
}
public String getNom(){
......
No preview for this file type
public class Autruche extends Vegetarien{
int nbPlumes;
private int nbPlumes;
static final int QTEJOUR=5;
public Autruche(String nom, double poids, int nbPlumes){
......@@ -22,6 +22,6 @@ public class Autruche extends Vegetarien{
@Override
public String toString(){
return super.toString()+"; nombre de plumes : "+nbPlumes+"; cri : "+getCri();
return "Autruche : "+super.toString()+"; nombre de plumes : "+nbPlumes+"; cri : "+getCri();
}
}
public abstract class Carnivore extends Animal{
int quantiteViande;
double quantiteViande;
public Carnivore(String nom, double poids,int quantiteViande){
public Carnivore(String nom, double poids,double quantiteViande){
super(nom,poids);
this.quantiteViande=quantiteViande;
}
......
......@@ -12,6 +12,6 @@ public class Chimpanze extends Vegetarien{
@Override
public String toString(){
return super.toString();
return "Chimpanze : "+super.toString()+"; Cri : "+getCri();
}
}
File added
public class Orque extends Carnivore{
static final double QTEJOUR_PAR_KG=0.1;
public Orque(String nom, double poids){
super(nom,poids,QTEJOUR_PAR_KG*poids);
}
public void setPoids(double p){
super.setPoids(p);
this.quantiteViande=p*QTEJOUR_PAR_KG;
}
@Override
public String getCri(){
return "Sifflement";
}
@Override
public String toString(){
return "Orque : "+super.toString()+"; Cri : "+getCri();
}
}
public class TestAnimaux{
public static void main(String[] args) {
Animal a=new Aigle("Francois",70,20);
Animal b=new Chimpanze("Florent",50);
Animal c=new Autruche("Nicolas",150,200);
System.out.println(a);
System.out.println(b);
System.out.println(c);
Animal d=new Autruche("Francois",150,200);
System.out.println(d.equals(a));
System.out.println(d==a);
}
}
public class TestZoo{
public static void main(String[] args) {
Zoo z=new Zoo("Minatec");
Animal a=new TigreBengale("Fantome",120,40);
Animal b=new Autruche("Ann",50,20);
Animal c=new Chimpanze("Chita",30);
Animal d=new Aigle("Roquette",5,200,2);
Animal e=new Orque("Azog",9000);
z.ajoute(a);
z.ajoute(b);
z.ajoute(c);
z.ajoute(d);
z.ajoute(e);
System.out.println(a.getCout());
System.out.println(b.getCout());
System.out.println(c.getCout());
System.out.println(d.getCout());
System.out.println(e.getCout());
System.out.println(z.coutTotal());
System.out.println(z);
}
}
public class TigreBengale extends Carnivore{
static final int QTEJOUR=4;
private int nbRayures;
public TigreBengale(String nom, double poids, int nbRayures){
super(nom,poids,QTEJOUR);
this.nbRayures=nbRayures;
}
@Override
public String getCri(){
return "Feulement";
}
@Override
public String toString(){
return "Tigre du Bengale : "+super.toString()+"; nombre de rayures : "+nbRayures+"; Cri : "+getCri();
}
}
public class TigreBlanc extends Carnivore{
static final int QTEJOUR=4;
private int nbRayures;
public TigreBlanc(String nom, double poids, int nbRayures){
super(nom,poids,QTEJOUR);
this.nbRayures=nbRayures;
}
@Override
public String getCri(){
return "Feulement";
}
@Override
public String toString(){
return "Tigre Blanc : "+super.toString()+"; nombre de rayures : "+nbRayures+"; Cri : "+getCri();
}
}
No preview for this file type
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