[Solved]1 Suppose Product Class Setter Set Productprice Instance Variable Defined Double Use Sette Q37224588


1. Suppose the Product class has a setter to set theproductPrice instance variable defined as a double. Use this setterto set the value of the Product object at index 3 of the arrayListproductList
//Set the element 4’s product’s price
productList.get(3).setProductPrice(2.50);
Suppose the Student object has a setter called setStudentName toset the value of instance variable studentName of type string. Setthe studentName of the Student object at index 2, in studentListarrayList .
Answer:
2. Suppose we want to search the productList arrayList forproductID equal to 22. We needt o find the index of this productID,if the product exists, and then print out the productName at thisgiven productID. To do this we search the array list to find theindex of the given product ID as follows:
//Search for a particular Product’s index using ProductID
int prodIndex = -1; // give an initial values that is less than0
for(int k = 0; k < productList.size(); k++)
{
p = productList.get(k);
if(p.getProductID() == 22)
{
prodIndex = k;
System.out.println(” Product 22 found!” + ” Product Name is: ” +p.getProductName());
}
}
if (prodIndex == -1)
System.out.println(” Product 22 not found!”);
Using the above example, search through the studnetList arraylist for studentID equal to 23. If this id is found, print thestudnetName using getStudnetName() method.
Answer:
Expert Answer
Answer to 1. Suppose the Product class has a setter to set the productPrice instance variable defined as a double. Use this sette… . . .
OR

