/**
 * Represents a Farm (poorly).  
 * Primarly used to demonstrate pass by value for object variables
 *
 * @author CSCI209
 */
public class Farm {

    private String name;

    public Farm(String name) {
        this.name = name;
    }

    /**
     * c copies the value of the variable passed into the method
     * (i.e., the memory location of the Chicken)
     * so the Chicken object that is referenced by c will be
     * changed after this method returns.
     */
    public void feedChicken(Chicken c) {
        c.setWeight( c.getWeight() + .5 );
    }
    
    /**
     * c copies the value of the variable passed into the method.
     * When c is then assigned to a _new_ Chicken object, c now refers to 
     * a new address.  The original variable passed in does not change,
     * so calling mutators on the new Chicken object do not affect the
     * original Chicken object passed in.
     */
    public void feedChickenNew(Chicken c) {
        c = new Chicken(c.getName(), 
                        c.getHeight(), c.getWeight() );
        c.setWeight( c.getWeight() + .5);
    }

    public static void main(String[] args) {
        Farm farm = new Farm("OldMac");
        Chicken sal = new Chicken("Sallie Mae", 45, 5.0);
        System.out.println(sal.getWeight());
        farm.feedChicken(sal);
        // weight of Sal will be higher.
        System.out.println(sal.getWeight());
        
        farm.feedChickenNew(sal);
        // sal is not affected
        System.out.println(sal.getWeight());
    }

}