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. It provides essential Chicken functionality, like feeding it.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Chicken(String name, int h, double weight)
    Constructs a new Chicken object with the characteristics 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
    Sets the name of the chicken, only if the given name is not empty.

    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 h, double weight)
      Constructs a new Chicken object with the characteristics as specified by the parameters.
      Parameters:
      name - the name of the chicken
      h - 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 name)
      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

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