Question
I need new and unique answers, please. (Use your own words, don't copy and paste), Please Use your keyboard (Don't use handwriting) Thank you.. Q1:
I need new and unique answers, please. (Use your own words, don't copy and paste), Please Use your keyboard (Don't use handwriting) Thank you..
Q1:
Suppose in the hierarchy of animal classes (see Fig 1) you forget to define the Zebra class. Now you have to add it after all the classes are created. How can you create the Zebra class in the best possible way to avoid redundancy and what do you think is the worst case of the Zebra class creation? (Hint: Zebra is similar to Horse in characteristics )
Write the code to add the Zebra class.
________
Q2:
Given a positive integer number says n, write a java program to print the first n squared numbers recursively.
Sample run 1:
Enter the value of n: 5 -------------------------------------
First 5 square numbers are: 1 4 9 16 25
Sample run 2:
Enter the value of n: 10 ------------------------------------- First 10 square numbers are: 1 4 9 16 25 36 49 64 81 100
Sample run 3:
Enter the value of n: 12 ------------------------------------- First 12 square numbers are: 1 4 9 16 25 36 49 64 81 100 121 144
________
Q3:
Consider the following interface:
interface Validate
{
boolean check(Object o);
}
Classes that implement Validate interface, check against specific conditions to evaluate the object O. For example, a class validateAge checks if a birth year indicated by the persons age is over 18 years old or not. If v is a validateAge object, then v.check(2001) returns true, and v.check(2003) returns false.
Write the class validateAge, and recall casting from a type to another.
Animal Animal Horse Producer Pig Cow Sheep Goat Fig 1: Animal class hierarchy he structure of the Animal and the Horse class is given as: public class Animal { public void eat) { System.out.println (grass or meat"); public class Horse extends Animal { public void eat() { System.out.println("Eats grass"); public void speak(){ System.out.println("Neigh");}Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started