SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,kenrick Mock
Chapter:
Inheritance
Exercise:
Programming Projects
Question:9 | ISBN:9780132830317 | Edition: 5

Question

Programming Project 6.18 asked you to use an array of Strings to store the fruits and vegetables shipped in a BoxOfProduce object for a CSA farm.

Modify your solution further by creating a Produce class. This class should have an instance variable of type String for the name, appropriate constructors, and a public toString() method. Then create a Fruit and a Vegetable class that are derived from Produce. These classes should have constructors that take the name as a String and invoke the appropriate constructor from the base class to set the name.

Next, modify the text file of produce so it indicates whether each item is a fruit or a vegetable. Here is one possible organization, although you can use others:

Broccoli,Vegetable

Tomato,Fruit

Kiwi,Fruit

Kale,Vegetable

Tomatillo,Fruit

Finally, modify the BoxOfProduce class so it creates an array of type Produce instead of type String . The class should read the produce from the text file and create instances of either Fruit or Vegetable , with the appropriate name, in the array. After a box is finished, loop through the contents of the array and output how many fruit and how many vegetables are in the box. The rest of the program should behave the same as the solution to Programming Project 6.18.


TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Sorry the answer is not available at the moment…

If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.

Spread the 'tradition of sharing'.