Question: you will be given a FruitFruit class. From this, you will subclass FruitFruit to make a Lemon and Pear class. The Fruit class has the
you will be given a FruitFruit class. From this, you will subclass FruitFruit to make a Lemon and Pear class.
The Fruit class has the following fields:
peel (boolean): tells us if we can eat the skin (false) or must peel the fruit (true)
colour (String): Colour of the outside of the fruit
It has a constructor and five methods, including a toString()method, 2 getters and 2 setters. Details follow.




import java.util.*;
public class PoD
{
public static void main (String [] arg )
{
Scanner in = new Scanner( System.in );
String fruitType = in.next();
boolean peelSkin = in.nextBoolean();
String skinColour = in.next();
Fruit newFruit;
if (fruitType.equals("PEAR")) //Pear
{
newFruit = new Pear();
}
else //Lemon
{
newFruit = new Lemon();
}
System.out.println("-------"+fruitType+"-------");
System.out.println(newFruit);
newFruit.setPeel(peelSkin);
newFruit.setColour(skinColour);
System.out.println("-------UPDATED-------");
System.out.println(newFruit);
System.out.print("END OF OUTPUT");
in.close();
}
}
Fruit class Fruit #peel : boolean #colour : String +getPeelO: boolean Returns the value of the field peel +getColourO String Returns the value of the field colour +5etPeel() : boolean Sets the value of peel +setColourO : String Sets the value of colour +toStringO String Returns details of the Fruit object
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
