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) 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
Get step-by-step solutions from verified subject matter experts
