In this project, you need to create the following; MovingAnimalInterface : An in
ID: 3677761 • Letter: I
Question
In this project, you need to create the following;
MovingAnimalInterface : An interface with move() method.
Bird : A bird class implementing MovingAnimalInterface interface.
Cat : A cat class implementing MovingAnimalInterface interface.
P8 : A tester class. In the main method, create an array of MovingAnimalInterface with length 3.
Assign the 3 objects below in the order given below;
• arr[0] = new Cat("Garfield");
• arr[1] = new Bird("Tweety");
• arr[2] = new Cat("Sylvester");
In the main method, use an enhanced for-loop (also known as, for-each loop).
For each item of the array, call the move method.
Sample Output:
I am the cat Garfield. I run.
I am the bird Tweety. I fly.
I am the cat Sylvester. I run.
Should have 4 .java files.
Explanation / Answer
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
String name;
name = n;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
String name;
name = n;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
file4 :P8.java
class P8{
public static void main(String args[]){
MovingAnimalInterface[] arr = new MovingAnimalInterface[3];
arr[0] = new Cat("Garfield");
arr[1] = new Bird("Tweety");
arr[2] = new Cat("Sylvester");
for (MovingAnimalInterface item : arr) {
item.move();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.