Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 )

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Distributed Relational Database Architecture Connectivity Guide

Authors: Teresa Hopper

4th Edition

0133983064, 978-0133983067

Students also viewed these Databases questions

Question

How are the securities lending market regulated?

Answered: 1 week ago

Question

Does it use a maximum of two typefaces or fonts?

Answered: 1 week ago