Class Chicken
java.lang.Object
Chicken
A Java class that represents a chicken. The state of the chicken is
its name, height and weight.
Difference from previous version: added overloaded constructor and
overriden toString and equals methods.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Determines if the Object o is equivalent to this Chicken, based on their name, height, and weight.void
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
setHeight
(int h) Sets the height of the chicken, in cmvoid
Sets the name of the chickenvoid
setWeight
(double w) Sets the weight of the chicken, in poundstoString()
Returns a string representation of the chicken.
-
Constructor Details
-
Chicken
Constructs 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) Constructs a new Chicken object with the 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>
\tweight: <weight> pounds
\theight: <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
-