Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

image text in transcribed

image text in transcribed

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 interface and the compare Tomethod. Point pl is said to be greater than point p2 if pl.w > p2.w or if pl.w = =p2.w and pl.z>p2.z. Override the toString( method to return a string as [w value, z value]. Implement the Cloneable interface and clone method. . Page 2 of 4 Complete and run your program using the following code: public class Ques_02 { public static void main(String[] args) { Point pl = new Point(3, 4); Point p2 = new Point(3.4, 1.4); System.out.println(p1.equals(p2)); System.out.println(p1.equals(p1)); System.out.println(p1.compareTo(p2)); System.out.println(p2.compareTo(p1)); Point p3 = (Point) (p1.clone(): System.out.println(p3.equals(p1)); System.out.println(p3): } Submission Follow these instructions carefully or you risk penalties up to 100% of your grade! You are to submit 3 files for each question, separately: 2. 1. The Java project that contains your assignment 2. A text or word processed document containing all of your source code 3. A text file (.txt) of the output using the "Save to File" button from the Console (output window). 1. Java Project: . Your project file should ONLY contain the files needed for this current assignment. It should NOT contain any other projects or files. Your project must be a valid Java project. No other project types will be accepted. 2. Document of Source: You must also copy and paste all of your source code from both of your classes into a plain text file(e.g. .TXT) or Word document (e.g. DOC/.DOCX). Page 3 of 4 You don't have to format this code - it's used by Turnitin (the originality checker in SLA which is a piece of software that checks your submission for plagiarism against other submissions in the college, in other colleges, from the web, and various other sources). { f 11 Q

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_2

Step: 3

blur-text-image_3

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 2 Lnai 6322

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215882X, 978-3642158827

More Books

Students also viewed these Databases questions