Skip to content
Snippets Groups Projects
Commit 2a263656 authored by Alexandre's avatar Alexandre
Browse files

tpOO-07::exo-volailles

parent 62412bdb
No related branches found
No related tags found
No related merge requests found
package tpOO.tp07;
public class BreedingFarm {
}
package tpOO.tp07;
public class Duck extends Poultry{
public static double priceKg = 1.5;
public static double slaughterTreshold = 5.0;
Duck(int identity, double weight){
super(identity, weight);
this.type = "Duck";
}
}
package tpOO.tp07;
public class Goose extends Poultry{
public static double priceKg = 4.0;
public static double slaughterTreshold = 10.0;
Goose(int identity, double weight){
super(identity, weight);
this.type = "Goose";
}
}
package tpOO.tp07;
public class Hen extends Poultry{
public static double priceKg = 1.0;
public static double slaughterTreshold = 3.5;
Hen(int identity, double weight){
super(identity, weight);
this.type = "Hen";
}
}
package tpOO.tp07;
public interface IForceFeeding {
}
package tpOO.tp07;
public class Poultry {
protected int identity;
protected double weight;
String type;
protected Poultry(int identity, double weight){
this.identity = identity;
this.weight = weight;
}
public int getIdentity(){
return this.identity;
}
public void setIdentity(int identity){
this.identity=identity;
}
public double getWeight(){
return this.weight;
}
public double getPrice(){
if(this.type=="Hen"){
return Hen.priceKg * this.weight;
}
if(this.type=="Duck"){
return Duck.priceKg * this.weight;
}
return Goose.priceKg * this.weight;
}
public void setWeight(double weight){
this.weight = weight;
}
@Override
public String toString(){
return this.type + " [" + this.identity + ", " + this.weight + "]";
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment