Class Chicken
java.lang.Object
Chicken
A Java class that represents a chicken. The state of the chicken is
its name, height and weight. There is also a static variable
representing the name of the farm that the Chickens are on.
Added overrided methods: toString, equals
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic doublethe amount of weight difference we are okay withstatic final Stringthe name of the farm the chickens are on -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanDetermines if the Object o is equivalent to this Chicken, based on their name, height, and weight.voidfeed()Feeds the chicken, increasing the chicken's weight and heightintReturns the chicken's height, in centimetersgetName()Returns the chicken's namedoubleReturns the chicken's weight, in poundsstatic voidTests the Chicken classvoidsetHeight(int h) Sets the height of the chicken, in cmvoidSets the name of the chickenvoidsetWeight(double w) Sets the weight of the chicken, in poundstoString()Returns a string representation of the chicken.
-
Field Details
-
FARM
the name of the farm the chickens are on- See Also:
-
ERROR_TOLERANCE
public static double ERROR_TOLERANCEthe amount of weight difference we are okay with
-
-
Constructor Details
-
Chicken
Create a new Chicken object with the charactistics as specified by the parameters.- Parameters:
name- the name of the chickenheight- the height of the chicken in centimetersweight- the weight of the chicken in pounds
-
Chicken
public Chicken(int height, double weight) Default name: "Bubba"; height and weight specified by parameters- Parameters:
height- the height of the chicken in centimetersweight- the weight of the chicken in pounds
-
-
Method Details
-
getHeight
public int getHeight()Returns the chicken's height, in centimeters- Returns:
- the height of the chicken, in centimeters
-
getWeight
public double getWeight()Returns the chicken's weight, in pounds- Returns:
- the weight of the chicken, in pounds
-
getName
Returns the chicken's name- Returns:
- the name of the chicken
-
feed
public void feed()Feeds the chicken, increasing the chicken's weight and height -
setName
Sets the name of the chicken- Parameters:
n- the name of the chicken
-
setHeight
public void setHeight(int h) Sets the height of the chicken, in cm- Parameters:
h- the height of the chicken, in cm
-
setWeight
public void setWeight(double w) Sets the weight of the chicken, in pounds- Parameters:
w- the weight of the chicken, in pounds
-
toString
Returns a string representation of the chicken. Format:
Chicken name: <name>
weight: <weight> pounds
height: <height> cmWeight is displayed to one decimal place
-
equals
Determines if the Object o is equivalent to this Chicken, based on their name, height, and weight. -
main
Tests the Chicken class- Parameters:
args- the command-line arguments
-