Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose that there is a big farm in California that supplies the majority of the Grocery stores in the twin cities with vegetables and fruits.

Suppose that there is a big farm in California that supplies the majority of the Grocery stores in the twin cities with vegetables and fruits. The stores submit their orders and receive the shipment a week later. Based on the size of the orders, the farm management decides on the size of the truck to load.

Create a Produce class that have an instance variable of type String for the name, appropriate constructors, appropriate accessor and mutator methods, 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. Also, they should override toString method to display the name of the produce and its type. For instance, Mango is a Fruit and Cauliflower is a Vegetable.

Finally, create a class called TruckOfProduce that will keep track of the boxes of Vegetables and Fruits added in to the truck. This class should use an array of Produce to store both vegetables and fruits. Also, it should have the following:

Constructor that accepts an integer to initialize the array of Produce

addProduce method that adds either fruit or vegetable to the array

search method that accepts a name string, which can be either the name of a fruit or vegetable, and returns true if the name exists. Otherwise, it returns false.

remove method that accepts a produce object and returns true if the produce is found and removed successfully. Otherwise, it returns false.

toString method that returns all the produce from in the truck.

ensureCapacity method this is a void method. When this method is called it will double the size of the array and copy all the content of the smaller array in to this bigger array.

For instance, one could initialize the array to hold 1000 boxes of vegetables and fruits. What will happen if you try to add one more box (1001)? Of course, you will get an ArrayIndexOutOfBound error. So, thing about ensureCapacity as the method that will solve ArrayIndexOutBound error.

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_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

Define knowledge and describe the different types of knowledge

Answered: 1 week ago

Question

7. It is advisable to do favors for people whenever possible.

Answered: 1 week ago