Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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: 27Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started