object oriented programming java homework question about abstracting and interfaces 2. Definition of a hierarchy of fruits
Fantastic news! We've Found the answer you've been seeking!
Question:
object oriented programming java homework question about abstracting and interfaces
Transcribed Image Text:
2. Definition of a hierarchy of fruits is given below. a. Fruit contains an abstract method getVitamin() that returns String. Fruit contains a String field color. Fruits are Apple, Banana, Strawberry and Blackberry. Apples are green, bananas are yellow, strawberries are red, blackberries are black. All these classes have zero parameter constructors. o o o Apple's vitamins are "A B12". Banana's vitamins are "CD". Strawberry's vitamins are "B5 E". Blackberry's vitamins are "C K". Apples and bananas grow on trees. All tree fruits provide a void method named peel(). Define a class (or interface?) named Tree Fruit that has method peel. Make Apple and Banana extend (or implement?) TreeFruit. o When an Apple is being peeled, it prints out "Peeling an apple.". When a Banana is being peeled, it prints out "Peeling a banana.". Strawberries and blackberries grow on the ground. All ground fruits provide a void method named pick (). Define a class (or interface?) named Ground Fruit that has method pick. Make Strawberry and Blackberry extend (or implement?) GroundFruit. o When a Strawberry is being picked, it prints out "Picking a strawberry." o When a Blackberry is being picked, it prints out "Picking a blackberry." Implement the classes. b. Implement a method named prepare Fruits that takes a list of fruits and invokes tree fruits' peel method and ground fruits' pick method. i.e. You have to distinguish tree fruits from ground fruits. public static void prepareFruits ArrayList fruits) { // IMPLEMENT THIS METHOD } c. Use the following main method to test your code. public static void main(String[] args) { ArrayList fruits = new ArrayList (); fruits.add(new Apple()); fruits.add(new Banana()); fruits.add(new Strawberry()); fruits.add(new Blackberry()); prepareFruits (fruits); 2. Definition of a hierarchy of fruits is given below. a. Fruit contains an abstract method getVitamin() that returns String. Fruit contains a String field color. Fruits are Apple, Banana, Strawberry and Blackberry. Apples are green, bananas are yellow, strawberries are red, blackberries are black. All these classes have zero parameter constructors. o o o Apple's vitamins are "A B12". Banana's vitamins are "CD". Strawberry's vitamins are "B5 E". Blackberry's vitamins are "C K". Apples and bananas grow on trees. All tree fruits provide a void method named peel(). Define a class (or interface?) named Tree Fruit that has method peel. Make Apple and Banana extend (or implement?) TreeFruit. o When an Apple is being peeled, it prints out "Peeling an apple.". When a Banana is being peeled, it prints out "Peeling a banana.". Strawberries and blackberries grow on the ground. All ground fruits provide a void method named pick (). Define a class (or interface?) named Ground Fruit that has method pick. Make Strawberry and Blackberry extend (or implement?) GroundFruit. o When a Strawberry is being picked, it prints out "Picking a strawberry." o When a Blackberry is being picked, it prints out "Picking a blackberry." Implement the classes. b. Implement a method named prepare Fruits that takes a list of fruits and invokes tree fruits' peel method and ground fruits' pick method. i.e. You have to distinguish tree fruits from ground fruits. public static void prepareFruits ArrayList fruits) { // IMPLEMENT THIS METHOD } c. Use the following main method to test your code. public static void main(String[] args) { ArrayList fruits = new ArrayList (); fruits.add(new Apple()); fruits.add(new Banana()); fruits.add(new Strawberry()); fruits.add(new Blackberry()); prepareFruits (fruits);
Expert Answer:
Posted Date:
Students also viewed these programming questions
-
A particular automatic sprinkler system has two different types of activation devices for each sprinkler head. One type has a reliability of 0.9; that is, the probability that it will activate the...
-
Nintendo Company reports the following income statement accounts for the year ended March 31, 2008. (Japanese Yen in millions.) Net sales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....
-
Calculate the moment of inertia around the C 2 axis (the bisector of the OOO angle) and the corresponding rotational constant of an 16 O 3 molecule (bond angle 117; OO bond length 128 pm).
-
Part One: Economic Order Quantity Compute the economic order quantity for oats based upon the following information related to a manufacturer of granola; round to the nearest whole unit. Assume that...
-
The following items present a sample of business activities involving Dry Cleaner Corporation (DCC) for the year ended December 31. DCC provides cleaning services for individual customers and for...
-
Company A is requesting a credit facility to finance seasonal buildups of current assets. The company's projections show a seasonal low period of about 3 months. What type of facility would you...
-
Provide an overview of the Psychoneuroimmunological Model Borysenko in 600 words. Also, provide bullet points of your findings.
-
Fill in the Blank. Although an undamped vibration absorber removes the original resonance peak of the response, it introduces ____________ new peaks.
-
Does spring mounting always reduce the vibration of the foundation of a machine?
-
True or False. The transmissibility is also called the transmission ratio.
-
Is the shaking force proportional to the square of the speed of a machine? Does the vibratory force transmitted to the foundation increase with the speed of the machine?
-
Reduce transmission of excitation force from one part to another a. Introduce damping b. Use vibration isolator c. Add vibration absorber d. Avoid resonance
-
Erie Company manufactures a mobile fitness device called the Jogging Mate. The company uses standards to control its costs. The labor standards that have been set for one Jogging Mate are as follows:...
-
Coastal Refining Company operates a refinery with a distillation capacity of 12,000 barrels per day. As a new member of Coastal's management team, you have been given the task of developing a...
-
While designing a mixer-settler extraction system, you obtain a mass transfer correlation from a book. Unfortunately, the book does not explain which model was used. Which model would you use to...
-
Explain why mass transfer correlations for co-flow cannot be used for countercurrent flow.
-
Why are mass transfer coefficients from clean drops higher than mass transfer coefficients in dirty systems? What is the practical significance of this?
Study smarter with the SolutionInn App