Question: using java Create three classes - Product with fields name (String) and quantity (of type int); - Box with fields id (String) and prods -

 using java Create three classes - Product with fields name (String)

using java

Create three classes - Product with fields name (String) and quantity (of type int); - Box with fields id (String) and prods - array of Products; - Storage with only one field boxes - array of Boxes. All fields must be private. Provide necessary constructors and getters. In class Storage add a method totQuant which counts (and returns as an int) the total quantity of product the name of which (String) is passed as an argument to the method. In a separate class define function main public static void main (String [] args) \{ Box box1 = new Box("Box1", new Product [] new Product("Carrot", 15), new Product("Apples", 20) \}); Box box2 = new Box("Box2", new Product []\{ new Product ("Potato", 10), new Product ("Carrot", 12) \}); Storage sto = new Storage( new Box[] \{box1, box2\}); System. out.println("Tot. quantity of product: " + s sto.totQuant("Carrot")); which, for this example, should print Tot. quantity of product: 27

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!