Problem

Visit www.myprogramminglab.com to complete select exercises online and get instant feedbac...

Visit www.myprogramminglab.com to complete select exercises online and get instant feedback.

Exercise

Programming Project 1 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, VegetableTomato, FruitKiwi, FruitKale, VegetableTomatillo, 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 1.

Project 1

Visit www.myprogramminglab.com to complete select exercises online and get instant feedback.

Exercise

Programming Project asked you to create a BoxOfProduce class representing a box of produce to deliver from a CSA farm. The box contained exactly three items. Modify the class so it uses an array of type String to represent the items in the box. You can still start with three random items to place in the box, but your menu should be modified to allow the user to add additional items and still substitute one item for another. You will likely need to modify the constructor of the BoxOfProduce class and also add new methods.

Project

Visit www.myprogramminglab.com to complete select exercises online and get instant feedback.

Exercise

Your Community Supported Agriculture (CSA) farm delivers a box of fresh fruits and vegetables to your house once a week. For this Programming Project, define the class BoxOfProduce that contains exactly three bundles of fruits or vegetables. You can represent the fruits or vegetables as three instance variables of type String. Add an appropriate constructor, accessor, and mutator methods. Also write a toString() method that returns as a String the complete contents of the box.

Next, write a main method that creates a BoxOfProduce with three items randomly selected from this list:

BroccoliTomatoKiwiKaleTomatillo

This list should be stored in a text file that is read in by your program. For now you can assume that the list contains exactly five types of fruits or vegetables.

Do not worry if your program randomly selects duplicate produce for the three items. Next, the main method should display the contents of the box and allow the user to substitute any one of the five possible fruits or vegetables for any of the fruits or vegetables selected for the box. After the user is done with substitutions, output the final contents of the box to be delivered. If you create additional methods to select the random items and to select valid substitutions, then your main method will be simpler to write.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 7