forked from APCSLowell/OldMacDonald
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFarm.java
More file actions
25 lines (25 loc) · 700 Bytes
/
Copy pathFarm.java
File metadata and controls
25 lines (25 loc) · 700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Farm
{
private Animal[] aBunchOfAnimals;
public Farm()
{
aBunchOfAnimals=new Animal[3];
aBunchOfAnimals[0]=new NamedCow("cow", "Cowlvin", "moo");
aBunchOfAnimals[1]=new Chick("chick", "cheep", "cluck");
/*if((int)(Math.random()*2==0))
{
aBunchOfAnimals[1]=new Chick("chick", "cluck");
}else{
aBunchOfAnimals[1]=new Chick("chick", "cheep");
}*/
aBunchOfAnimals[2]=new Pig("pig", "oink");
}
public void animalSounds()
{
for(int nI=0;nI<aBunchOfAnimals.length;nI++)
{
System.out.println(aBunchOfAnimals[nI].getType()+" goes "+aBunchOfAnimals[nI].getSound());
}
System.out.println("The cow is known as "+((NamedCow)(aBunchOfAnimals[0])).getName());
}
}