Class Chicken
java.lang.Object
Chicken
A Java class that represents a Chicken. The state of the chicken is
its name, height and weight. It provides essential Chicken
functionality, like feeding it.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
feed()
Feeds the chicken, increasing the chicken's weight and heightint
Returns the chicken's height, in centimetersgetName()
Returns the chicken's namedouble
Returns the chicken's weight, in poundsstatic void
Tests the Chicken classvoid
Sets the name of the chicken, only if the given name is not empty.
-
Constructor Details
-
Chicken
Constructs a new Chicken object with the characteristics as specified by the parameters.- Parameters:
name
- the name of the chickenh
- 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, only if the given name is not empty.- Parameters:
name
- the non-empty new name of the chicken
-
main
Tests the Chicken class- Parameters:
args
- the command-line arguments
-