Answered step by step
Verified Expert Solution
Question
1 Approved Answer
object oriented programming java homework question about abstracting and interfaces 2. Definition of a hierarchy of fruits is given below. a. Fruit contains an abstract
object oriented programming java homework question about abstracting and interfaces
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);
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