Question: Please help with Java program output: Input: 5 Cheese; 1 1 Foil, 7 Socks, - 1 CallProduct.java - import java.util.ArrayList; import java.util.Scanner; public class CallProduct
Please help with Java program output:
Input:
Cheese; Foil, Socks,
CallProduct.java
import java.util.ArrayList;
import java.util.Scanner;
public class CallProduct
public static void mainString args
Scanner scnr new ScannerSystemin;
ArrayList productList new ArrayList;
int currPrice;
String currName;
int i;
Product resultProduct;
currPrice scnrnextInt;
while currPrice
resultProduct new Product;
currName scnrnext;
resultProductsetPriceAndNamecurrPrice currName;
productListaddresultProduct;
currPrice scnrnextInt;
resultProduct productList.get;
for i ; i productList.size; i
if productListgetigetPrice resultProduct.getPrice
resultProduct productList.geti;
System.out.printlnresultProductgetName: resultProduct.getPrice;
Product.java
public class Product extends CallProduct
private int price;
private String name;
public void setPriceAndNameint productPrice, String productName
price productPrice;
name productName;
public int getPrice
return price;
public String getName
return name;
Also, if you would be able to help understand how to run multiple classes in one java file, I would appreciate it I am using my own compiler for java code but I am having a hard time understanding how to run both CallProduct.java and Product.java at the same time, if it is even possible. Thank you.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
