Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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

image text in transcribed

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: " + 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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started