Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions