Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

-------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------- Subject: Computer Programming IIJava Note: P lease use the keyboard to write the answer and thank you for your help Question One 2

image text in transcribed

--------------------------------------------------------------------------------------------

image text in transcribed

-------------------------------------------------------------------------------------------------------------------------------

image text in transcribed

Subject: Computer Programming IIJava

Note: Please use the keyboard to write the answer and thank you for your help

Question One 2 Marks 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) Animal Horse Producer Pig | Cow Sheep Goat Fig 1: Animal class hierarchy If the 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() { Sxstem.out.println("Eats grass"); public void speak[X{ System.out.println("Neigh");} Write the code to add the Zebra class. Question Two ( 2 Marks) 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 | 1 Marks) Question Three Consider the following interface: interface Validate berdeen check [Object o); Classes that implement validate interface check against specific conditions to evaluate the object o. For example, a class validateAge check if a birth year indicate the person's age is over 18 years old or not. If v is a validateAge object, then icheck (2001) returns true, and v.check (2003) returns false. Write the class validateAge and recall casting from a type to another

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

Students also viewed these Databases questions

Question

Give an example of how response bias might occur.

Answered: 1 week ago