Please include all classes including driver. IN JAVA Suppose that there is a big farm in California...

90.2K

Verified Solution

Question

Programming

Please include all classes including driver.

IN JAVA

Suppose that there is a big farm in California that supplies themajority of the Grocery stores in the twin cities with vegetablesand fruits. The stores submit their orders and receive the shipmenta week later. Based on the size of the orders, the farm managementdecides on the size of the truck to load.

Create a Produce class that have an instance variable of typeString for the name, appropriate constructors, appropriate accessorand mutator methods, and a public toString() method. Then create aFruit and a Vegetable class that are derived from Produce. Theseclasses should have constructors that take the name as a String,the price (this is the price per box) as a double, the quantity asan integer, and invoke the appropriate constructor from the baseclass to set the name. Also, they should override toString methodto display the name of the produce, the price, and its type. Forinstance, Mango is a Fruit and Cauliflower is a Vegetable.

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

• Constructor that accepts an integer to initialize the array ofProduce

• addProduce method that adds either fruit or vegetable to thearray

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

• remove method that accepts a produce object and returns trueif the produce is found and removed successfully. Otherwise, itreturns false.

• computeTotal method that will return the total cost of all theproduce in the truck.

• toString method that returns all the produce from in thetruck.

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

For instance, one could initialize the array to hold 1000 boxesof vegetables and fruits. What will happen if you try to add onemore box (1001)? Of course, you will get an ArrayIndexOutOfBounderror. So, thing about ensureCapacity as the method that will solveArrayIndexOutBound error.

Then wrap it up with the driver class that tests all methods anddisplays the name of the produce, the price, and its type.

Answer & Explanation Solved by verified expert
4.4 Ratings (973 Votes)
Below is the java classes and the main driver class class Produce instance variable of the product name protected String name public constructors public ProduceString name thisname name public Produce thisname Accesors and mutators for the name public void setNameString name thisname name public String getName return thisname public String toString return thisname The Fruit class class Fruit extends Produce protected double price protected int quantity public FruitString name double price int quantity supersetNamename thisprice price thisquantity quantity public String toString This stores the string representation of the product String str str Name thisname n str Price thisprice n str Type Fruit return str Accesors and mutators public void setPricedouble price thisprice price public void setQuantityint quantity thisquantity quantity public double getPrice return thisprice public int getQuantity return    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students