Answered step by step
Verified Expert Solution
Question
1 Approved Answer
R : 1 Complete the program below that implement the following requirements The Animal class defines the sound method. This method is an abstract and
R : 1 Complete the program below that implement the following requirements The Animal class defines the sound method. This method is an abstract and will be implemented by an animal class. public abstract String sound 0: /** Return animal sound */ The Chicken class implements Edible to specify that chickens are edible. When a class implements an interface, it implements all the methods defined in the interface with the exact signature and return type. The Chicken class implements the howToEat method. Chicken also extends Animal to implement the sound method. 1 The Animal class and Their inheritance relationship is shown in Figure 1.1 Edible is a supertype for Chicken and Fruit. interface Edible Animal +howToEat(): String +soundO: String Animal is a supertype for Chicken and Tiger. Fruit is a supertype for Orange and Apple. Fruit Chicken Tiger Orange Apple FIGURE 1.1 Page 1 of 4 . . The Fruit class implements Edible. Since it does not implement howToEat method, Fruit must be denoted as abstract. The concrete subclasses of Fruit must implement the howTo Eat method. The Apple and Orange classes implement the howToEat method. The main method creates an array with objects and invokes the howToEat method if the element is edible and the sound method if the element is an animal. The Edible interface defines common behavior for edible objects. All edible objects have the howToEat method. Implement Animal class by Comparable interface and Cloneable Interface that implements two methods getWeight() and setWeight(). 1- Add the weight property in the Animal class with getter and setter methods 2- The two animals are compared based on their weights. . Use the following main method to run your program. public static void main(String[] args) { Animal() list = new Animal[5]: list[0] = new Chicken(); list[0].setWeight(4.5); list[1] = new Tiger(); list[1].setWeight(46.6): list[2] = new Chicken(); list[2].setWeight(1.5): list[3] = (Animal) (list[0].clone(): list[3].setWeight(7.5); list[4] = (Animal) (list[1].clone(); java.util.Arrays.sort(list): for (int i = 0; i interface and the compare Tomethod. Point pl is said to . & Q G : a Question 2 (10 marks): Design a class named Point that meets the following requirements: Two data fields w and z for representing a point with getter methods. A no-arg constructor that constructs a point for (0,0). A constructor that constructs a point with the specified w and z values. Override the equals method. Point pl is said to be greater than point p2 if pl.w = = P2.w and pl.z ==p2.z. Implement the Comparable
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