Define a class named AnimalHouse which represents a house for an animal. The AnimalHouse class takes a generic type parameter E. The AnimalHouse class contains: - A private E data field named animal which defines the animal of an animal house. - A default constructor that constructs an animal house object. - An overloaded constructor which constructs an animal house using the specified animal. - A method named getanimal () method which returns the animal field. - A method named setanimal (E obj) method which sets the animal with the given parameter. - A method named tostring() which returns a string representation of the animal field as shown in the examples below. Submit the AnimalHouse class in the answer box below assuming that all required classes are given.

Answers

Answer 1

The AnimalHouse class represents a house for an animal and contains fields and methods to manipulate and retrieve information about the animal.

How can we define the AnimalHouse class to accommodate a generic type parameter E?

To define the AnimalHouse class with a generic type parameter E, we can use the following code:

```java

public class AnimalHouse<E> {

   private E animal;

   public AnimalHouse() {

       // Default constructor

   }

   public AnimalHouse(E animal) {

       this.animal = animal;

   }

   public E getAnimal() {

       return animal;

   }

   public void setAnimal(E obj) {

       this.animal = obj;

   }

   public String toString() {

       return "Animal: " + animal.toString();

   }

}

```

In the above code, the class is declared with a generic type parameter E using `<E>`. The private data field `animal` of type E represents the animal in the house. The class has a default constructor and an overloaded constructor that takes an animal as a parameter and initializes the `animal` field accordingly. The `getAnimal()` method returns the animal field, and the `setAnimal(E obj)` method sets the animal with the given parameter. The `toString()` method overrides the default `toString()` implementation and returns a string representation of the animal field.

Learn more about AnimalHouse

brainly.com/question/28971710

#SPJ11


Related Questions

Other Questions
A piano tuner stretches a steel piano wire with a tension of 765 N. The steel wire has a length of 0. 600m and a mass of 4. 50g. What is the frequency f1 of the string's fundamental mode of vibration?Express your answer numerically in hertz using three significant figures For the given function, find (a) the equation of the secant line through the points where x has the given values and (b) the equation of the tangent line when x has the first value. y=f(x)=x^2+x;x=4,x=1 Suppose that in January a profit-maximizing firm has 25 employees. By February, the firm has decreased employment. One can infer that, when 25 employees are hired, theA) firm is losing market share.B) firm is minimizing losses.C) wage exceeds the value of the marginal product of labor.D) value of the marginal product of labor exceeds the wage A compound consisting of carbon and hydrogen consists of 67.90%carbon by mass. If the compound is measure to have a mass of 37.897Mg, how many grams of hydrogen are present in the compound? A split-plot design is also known as a:counterbalanced designmixed designTukey HSDblock design Assume that adults have 1Q scores that are normally distributed with a mean of 99.7 and a standard deviation of 18.7. Find the probability that a randomly selected adult has an 1Q greater than 135.0. (Hint Draw a graph.) The probabily that a randomly nolected adul from this group has an 10 greater than 135.0 is (Round to four decimal places as needed.) ogden and richards' triangle of meaning demonstrates visually that meanings are in a. words b. vocabularies c. nonverbal cues d. people recently, a regional tuna conservation committee suggested a five-year moratorium on tuna fishing in the pacific ocean, based on a study of the tuna population. which of the following is not correct? Explain the steps to generate machine code from a C/C++ code. 0.059 and 0.01 which is greater? The managers of Movies Plus, a large movie theater, want to practice third-degree price discrimination. The managers have learned that college students have an own price elasticity of demand of 4.0 for tickets at Movies Plus and adults have an own price elasticity of 2.0. If the managers have correctly determined the third-degree profit-maximizing price for adults is $10, what is the third-degree profit-maximizing price to charge students? Select one: A. $5.50 B. $12.00 C. $6.67 D. $15.00 Eight guests are invited for dinner. How many ways can they be seated at a dinner table if the table is straight with seats only on one side?A) 1B) 40,320C) 5040D) 362,880 Determine whether the following are data mining tasks. Provide explanations in favor of your answers. i) Computing the distance between two given data points ii) Predicting the future price of the stock of a company using historical records iii) Extracting the frequencies of a sound wave iv) Examining the heart rate of a patient to check abnormalities you are the ceo of a car manufacturing company, and realize that you may have to lay off 10,000 employees unless you take some other form of action. your chief financial officer comes up with two solutions: the first saves 6,000 jobs, and the second causes the company to lose 4,000 jobs. the first option sounds ideal at first; however, both options give the same outcome of cutting 4,000 jobs and saving 6,000 jobs. this example represents the concept of: n annual marathon covers a route that has a distance of approximately 26 miles. Winning times for this marathon are all over 2 hours. he following data are the minutes over 2 hours for the winning male runners over two periods of 20 years each. (a) Make a stem-and-leaf display for the minutes over 2 hours of the winning times for the earlier period. Use two lines per stem. (Use the tens digit as the stem and the ones digit as the leaf. Enter NONE in any unused answer blanks. For more details, view How to Split a Stem.) (b) Make a stem-and-leaf display for the minutes over 2 hours of the winning times for the recent period. Use two lines per stem. (Use the tens digit as the stem and the ones digit as the leaf. Enter NONE in any unused answer blanks.) (c) Compare the two distributions. How many times under 15 minutes are in each distribution? earlier period times recent period times john f. kennedy was able to carry texas and win the presidency in 1960 because . The following information was extracted from the books of KASTA Business on 31 December Additional information: (i) Withdrawal of RM5,000 from bank account has not been recorded. (ii) Advertising expenses RM65,000 were outstanding. (iii) All non-current assets are depreciated at 30% per annum, using reducing balance method. (v) Closing Inventory RM84,300 fully counted on 31 December. Required: Show all your working. (a) Prepare the Income Statement for the year ended 31 December 2021, and (b) the Balance Sheet as at 31 December 2021 . Is it possible to construct a contradictory sentence in LSL using no sentential connectives other than conjunction and disjunction? If so, give an example. If not, explain why not. Find an equation of the plane. the plane through the point (8,-3,-4) and parallel to the plane z=3 x-2 y determine the resultant force acting on the 0.7-m-high and 0.7-m-wide triangular gate