Declare Arraylist Named Productlist Five Elements Type Product Construct Elements Using 2 Q37223712

import java.util.ArrayList; public class TestProductList f public static void main (Stringi args) ArrayListくProduce> productL//Search for a particular Products index using ProductID int prodIndex- -1: / give an initial values that is less than for (

Declare an ArrayList named productList of five elements of typeProduct and construct the elements using the 2-argconstructor of Product class: this example is worked out foryou.

ArrayList productList = new ArrayList();

  

//Add objects to array List

productList.add(new Product(21,”Green-Tea”, 5.50));

productList.add(new Product(22,”Black-Tea”, 6.50));

productList.add(new Product(23,”Coffee-Keurig 20 oz”,15.00));

productList.add(new Product(24,”Sugar – store brand 1 lbs”,3.50));

productList.add(new Product(25,”Hot choc Store brand 1 lbs”,4.50));

Looking at the above example, declare

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.