Students, please be sure to log in. This site does not use cookies and does not track/store work submitted when not signed in.
Unit 6 Problems
Java Reference Sheet
MakeChicken2
Objective(s): Practice creating an array of objects and working with a java class.
Given the Chicken
class below, create 10 Chicken
objects stored in an array. Each object should have an age of 2.
Hint: This problem is asking you to visit your knowledge of java classes that have multiple constructors. How do you use one constructor over the other? What determines which one is called?
public class Chicken{
private double weight, age;
public Chicken(){ //the default constructor (no parameter)
weight = (int)(Math.random()*101);
}public Chicken(int param_age){ //a constructor that takes in a number
this(); //calls the default constructor
age = param_age;
}}