There are many kinds of animals. All animals make a sound and hear sounds made by...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
There are many kinds of animals. All animals make a sound and hear sounds made by other animals. Social animals are animals that have a name and two friends. They can talk to each other and spread rumors to others through friends. Dogs and cats are social animals, while tigers are not. You will create an inheritance hierarchy consisting of an interface and several animal classes. You must define an interface and an abstract class and leverage polymorphism. You will need to write the following methods in your program, though each class may not contain all of them. public String getName() public int getWeight() ⚫ public String makeSound() • Dogs make a "woof" sound. 。 Cats make a "meow" sound. Tigers make a "grrrrr" sound. ⚫ public void talk To(SocialAnimal animal) 。 When a dog talks to the specified animal, the dog barks and waves its tail. 。 When a cat talks to the specified animal, the cat purrs and smiles. ⚫ public void spreadRumor() 。 A social animal propagates a rumor on a social network through her friends. I.e., it talks to her friends who in turn talk to their friends and so on. More detailed instructions are provided in the Activities section. ⚫ public void hear(Animal[] animals) 。 When this animal hears from a group (animal_0, ....animal_n-2, animal_n-1} of the specified animals, animal_1 hears from animal_0, animal_2 hears from animal_1, and so on until this animal finally hears from animal_n-1. ⚫ public String toString() о Refer to the example in the next section. Examples The following method is provided in the AnimalMain.java file in your repository. public static void test1_2() { Animal tiger1 = new Tiger(300); Animal tiger2 = new Tiger(300); SocialAnimal happy = new Dog("Happy"); SocialAnimal lucky = new Dog ("Lucky"); SocialAnimal milky = new Cat ("Milky"); Animal[] animals = {tiger1, happy, lucky, tiger2, milky}; System.out.println("1. Testing makeSound and toString for(int i=0; i<animals.length; i++) { } System.out.println(animals [i].makeSound()); System.out.println(animals [i]); SocialAnimal yoda = new Cat ("Yoda"); .. "); System.out.println("\n2. Testing Yoda hearing animal sounds ..."); yoda.hear(animals); } The expected output of the method is as follows: 1. Testing makeSound and toString grrrrr 300 lb tiger [grrrrr] woof Happy [woof] woof Lucky [woof] grrrrr 300 lb tiger [grrrrr] meow Milky [meow] 2. Testing Yoda hearing animal sounds ... Happy hears grrrrr Lucky hears woof A tiger hears woof Milky hears grrrrr Yoda hears meow Activities 1. All files you write for the assignment should be in the "animal" package that has been provided in your repository. 2. Before writing code, complete the following UML diagram. You should commit your completed diagram to your repository (screenshot or PDF). <<abstract>> SocialAnimal name: String friend1: SocialAnimal firend2: SocialAnimal <<interface>> Animal + makeSound(): String + hear (Animal[] animals): void + <<create>> SocialAnimal(name: String) + setFriend1(friend1: Social Animal): void + setFriend2(friend2: SocialAnimal): void Cat Dog weight: int Tiger 3. Implement the classes in your UML diagram. If you have to change the classes so that they are different from the diagram, update the diagram too. 4. Complete the test3 method in AnimalMain.java. Use the provided social animals to create a social network depicted in the following diagram: Cat 2 Dog 4 Dog 5 Dog 2 Dog 1 Dog1 has Dog2 and Cat1 as friend1 and friend2, respectively. null Cat 3 Cat 1 Dog 3 null null Cat 4 Cat 5 null null null null null null null null A social animal has at most two friends. In the diagram above, A →B means that A has B as a friend. If dog1 starts gossiping, it talks to her friends, and friends of her friends talk to their friends, and so on. A rumor spreads through the population in the following order: dog1 → dog2, dog1 → cat1, dog2 → cat2, cat2 → dog4, cat2 → dog5, cat1 → cat3, cat1 → dog3, dog3 → cat4, dog3 → cat5. When test3 runs, your output should be 3. Testing dog1 spreading a rumor... Dog1 barks woof to Dog2 waving its tail. Dog1 barks woof to Cat1 waving its tail. Dog2 barks woof to Cat2 waving its tail. Cat2 purrs meow to Dog4 with a big smile. Cat2 purrs meow to Dog5 with a big smile. Cat1 purrs meow to Cat3 with a big smile. Cat1 purrs meow to Dog3 with a big smile. Dog3 barks woof to Cat4 waving its tail. Dog3 barks woof to Cat5 waving its tail. If * you are creating any other social network (for debugging), you may assume that it has a tree structure consisting of unique social animals like the example above. There are many kinds of animals. All animals make a sound and hear sounds made by other animals. Social animals are animals that have a name and two friends. They can talk to each other and spread rumors to others through friends. Dogs and cats are social animals, while tigers are not. You will create an inheritance hierarchy consisting of an interface and several animal classes. You must define an interface and an abstract class and leverage polymorphism. You will need to write the following methods in your program, though each class may not contain all of them. public String getName() public int getWeight() ⚫ public String makeSound() • Dogs make a "woof" sound. 。 Cats make a "meow" sound. Tigers make a "grrrrr" sound. ⚫ public void talk To(SocialAnimal animal) 。 When a dog talks to the specified animal, the dog barks and waves its tail. 。 When a cat talks to the specified animal, the cat purrs and smiles. ⚫ public void spreadRumor() 。 A social animal propagates a rumor on a social network through her friends. I.e., it talks to her friends who in turn talk to their friends and so on. More detailed instructions are provided in the Activities section. ⚫ public void hear(Animal[] animals) 。 When this animal hears from a group (animal_0, ....animal_n-2, animal_n-1} of the specified animals, animal_1 hears from animal_0, animal_2 hears from animal_1, and so on until this animal finally hears from animal_n-1. ⚫ public String toString() о Refer to the example in the next section. Examples The following method is provided in the AnimalMain.java file in your repository. public static void test1_2() { Animal tiger1 = new Tiger(300); Animal tiger2 = new Tiger(300); SocialAnimal happy = new Dog("Happy"); SocialAnimal lucky = new Dog ("Lucky"); SocialAnimal milky = new Cat ("Milky"); Animal[] animals = {tiger1, happy, lucky, tiger2, milky}; System.out.println("1. Testing makeSound and toString for(int i=0; i<animals.length; i++) { } System.out.println(animals [i].makeSound()); System.out.println(animals [i]); SocialAnimal yoda = new Cat ("Yoda"); .. "); System.out.println("\n2. Testing Yoda hearing animal sounds ..."); yoda.hear(animals); } The expected output of the method is as follows: 1. Testing makeSound and toString grrrrr 300 lb tiger [grrrrr] woof Happy [woof] woof Lucky [woof] grrrrr 300 lb tiger [grrrrr] meow Milky [meow] 2. Testing Yoda hearing animal sounds ... Happy hears grrrrr Lucky hears woof A tiger hears woof Milky hears grrrrr Yoda hears meow Activities 1. All files you write for the assignment should be in the "animal" package that has been provided in your repository. 2. Before writing code, complete the following UML diagram. You should commit your completed diagram to your repository (screenshot or PDF). <<abstract>> SocialAnimal name: String friend1: SocialAnimal firend2: SocialAnimal <<interface>> Animal + makeSound(): String + hear (Animal[] animals): void + <<create>> SocialAnimal(name: String) + setFriend1(friend1: Social Animal): void + setFriend2(friend2: SocialAnimal): void Cat Dog weight: int Tiger 3. Implement the classes in your UML diagram. If you have to change the classes so that they are different from the diagram, update the diagram too. 4. Complete the test3 method in AnimalMain.java. Use the provided social animals to create a social network depicted in the following diagram: Cat 2 Dog 4 Dog 5 Dog 2 Dog 1 Dog1 has Dog2 and Cat1 as friend1 and friend2, respectively. null Cat 3 Cat 1 Dog 3 null null Cat 4 Cat 5 null null null null null null null null A social animal has at most two friends. In the diagram above, A →B means that A has B as a friend. If dog1 starts gossiping, it talks to her friends, and friends of her friends talk to their friends, and so on. A rumor spreads through the population in the following order: dog1 → dog2, dog1 → cat1, dog2 → cat2, cat2 → dog4, cat2 → dog5, cat1 → cat3, cat1 → dog3, dog3 → cat4, dog3 → cat5. When test3 runs, your output should be 3. Testing dog1 spreading a rumor... Dog1 barks woof to Dog2 waving its tail. Dog1 barks woof to Cat1 waving its tail. Dog2 barks woof to Cat2 waving its tail. Cat2 purrs meow to Dog4 with a big smile. Cat2 purrs meow to Dog5 with a big smile. Cat1 purrs meow to Cat3 with a big smile. Cat1 purrs meow to Dog3 with a big smile. Dog3 barks woof to Cat4 waving its tail. Dog3 barks woof to Cat5 waving its tail. If * you are creating any other social network (for debugging), you may assume that it has a tree structure consisting of unique social animals like the example above.
Expert Answer:
Answer rating: 100% (QA)
create the inheritance hierarchy and implement the required methods you can follow this structure Define the interface for all animals interface Anima... View the full answer
Related Book For
Introduction to Probability
ISBN: 978-0716771098
1st edition
Authors: Mark Daniel Ward, Ellen Gundlach
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
To Premium From Actuarial Rating Advertising Sales Actuarial Premium 1e% 25% 15 60 The direct operating costs of the departments (including both variable and fixed costs) are Actuarial Premium rating...
-
Brenda's Bicycle and Surfboard Rentals leases quad-bikes each day from a supplier and rents them to customers who use them along Seawall Boulevard in Galveston, Texas. Each day, Brenda leases 30...
-
Find the volume of the solid generated by revolving the region bounded by the graphs of the equations about the line x = 5. x = y 2 , x = 4
-
What are the three parts of a make rule?
-
BOND SINKING FUNDS M. J. Adams Corporation pays $40,000 into a bond sinking fund each year for the future redemption of bonds. At the end of the first year, earnings on the sinking fund are $3,200....
-
thank you I've been having lots of troubles opening any documents in full they just appear as blank would you know why this is or perhaps be able to assist me
-
Three employees of the Horizon Distributing Company will receive annual pension payments from the company when they retire. The employees will receive their annual payments for as long as they live....
-
Discuss how and why Amazon might use budgets. within your discussion you are required ti discuss tge different types of budgets used and how it may be revised from time to time.
-
A critical debate and discussion of one of the area of impact (Social & Cultural, Economic & Touristic, Environmental, or Political) for Tomorrowland 2018
-
Mini ( 1000 Words ) - Unique no Copy Paste The development of payment infrastructure and its role as an enabler for a more inclusive and open digital payments ecosystem Background on the traditional...
-
Your sales presentation must be realistic. You will be selling products (not services). Only B2B selling situations are acceptable. No B2C! presentation must be oral. 1. Prepare script for both...
-
Mina, who was consistently employed for several years at her job as a school bus driver, was laid off in early 2021. As a result, she did not have sufficient 2021 earned income to qualify for EIC...
-
What effect would the usefulness of this new expensive drug have?
-
How does filtrate flow through the kidney? Order the flow of filtrate from glomerulus to toilet (urine) urinary bladder collecting duct minor calyx nephron loop (loop of Henle) descending limb -...
-
Recall that Chapter 8 described the binary search algorithm for finding a particular entry in an ordered list. The idea behind binary search is to begin looking in the exact center of the list. If...
-
Randomly open a 300-page book, and mark a page. What is the probability that the number of the page contains the lucky number 5?
-
As in Example 12.16, Jim and his brother both like chocolate chip cookies best. They have a jar of cookies with 5 chocolate chip cookies, 3 oatmeal cookies, and 4 peanut butter cookies. They are each...
-
Roll three distinguishable dice (e.g., assume that there is a way to tell them apart, for instance, that the dice are three different colors). There are 6 6 6 = 216 possible outcomes. For 3 < j <...
-
Portugal has a progressive personal income tax system. In 2016, tax rates on taxable income were \(14.5 \%\) on the first \( 7,035,21 \%\) on the next \( 13,065,37 \%\) on the next \( 20,100,45 \%\)...
-
In its 2016 International Tax Competitiveness Index report, the U.S.-based Tax Foundation ranked Estonia as having the most competitive tax system in the OECD, based in part on its \(20 \%\) flat tax...
-
A lump-sum tax is a fixed amount of tax per person. If a lump-sum tax, \(T\), raises the same amount of revenue for the government as a tax on earnings at the rate, \(t\), then \(t w H=T\), where...
Study smarter with the SolutionInn App