Class Chicken


public class Chicken extends Object
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.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Chicken(int height, double weight)
    Default name: "Bubba"; height and weight specified by parameters
    Chicken(String name, int height, double weight)
    Create a new Chicken object with the charactistics as specified by the parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Feeds the chicken, increasing the chicken's weight and height
    int
    Returns the chicken's height, in centimeters
    Returns the chicken's name
    double
    Returns the chicken's weight, in pounds
    static void
    main(String[] args)
    Tests the Chicken class
    void
    setHeight(int h)
    Sets the height of the chicken, in cm
    void
    Sets the name of the chicken
    void
    setWeight(double w)
    Sets the weight of the chicken, in pounds

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Chicken

      public Chicken(String name, int height, double weight)
      Create a new Chicken object with the charactistics as specified by the parameters.
      Parameters:
      name - the name of the chicken
      height - the height of the chicken in centimeters
      weight - 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 centimeters
      weight - 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

      public String 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

      public void setName(String n)
      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
    • main

      public static void main(String[] args)
      Tests the Chicken class
      Parameters:
      args - the command-line arguments