Question: Can you debug this code below? import java.io . * ; import java.util.Scanner; / / Product class to store Id , name, price, and quantity
Can you debug this code below?
import java.io;
import java.util.Scanner;
Product class to store Id name, price, and quantity and its getters and
setters and toString method
class Product
private int idNum;
private String name;
private double price;
private int quantity;
public Productint idNum, String name, double price, int quantity
this.idNum idNum;
this.name name;
this.price price;
this.quantity quantity;
public int getID
return idNum;
public void setIdint sID
idNum sID;
public String getName
return name;
public void setNameString sName
name sName;
public double getPrice
return price;
public void setPricedouble sPrice
price sPrice;
public int getQuantity
return quantity;
public void setQuantityint newQuantity
quantity newQuantity;
public String toString
return String.formatID: idNum Name:" name Price:" price Quantity:" quantity;
ProductCollection class with all required features
class ProductCollection
private Product collection;
private int count;
int maximumSize;
public ProductCollection
maximumSize ;
collection new ProductmaximumSize;
count ;
public void addProductint prodID, String prodName, double unitPrice, int prodQty
if count maximumSize
collectioncount new ProductprodID prodName, unitPrice, prodQty;
count;
else
increaseSize;
collectioncount new ProductprodID prodName, unitPrice, prodQty;
count;
public void increaseSize
maximumSize maximumSize ;
Product prdt new ProductmaximumSize;
for int i ; i count; i
prdti collectioni;
collection prdt;
public int indexOfint prodID
int flag result ;
for int i ; i count; i
if prodID collectionigetID
result i;
flag ;
if flag
result ;
return result;
public void changePriceint prodID, double newPrice
int ind indexOfprodID;
if ind
collectionindsetPricenewPrice;
public void buyProductint prodID, int qty
int ind indexOfprodID;
if ind
collectionindsetQuantitycollectionindgetQuantity qty;
else
System.out.printlnThe product ID is not in the list.";
public void sellProductint prodID, int qty
int ind indexOfprodID;
if ind
collectionindsetQuantitycollectionindgetQuantity qty;
else
System.out.printlnThe product ID is not in the list.";
public void deleteProductint prodID
int ind indexOfprodID;
if ind
for int i ind; i count ; i
collectioni collectioni ;
count;
else
System.out.printlnThe product ID is not in the list.";
public void displayProductint prodID
int ind indexOfprodID;
if ind
System.out.printlnProduct Name:" collectionindgetName Price:" collectionindgetPrice Quantity:" collectionindgetQuantity;
else
System.out.printlnThe product ID is not in the list.";
public String createOutputFile
try
File file new FileproductUpdatetxt;
file.createNewFile;
catch IOException e
System.out.printlne;
return "productUpdate.txt;
public String toString
String str "The products in Collection.
;
for int i ; i count; i
str str collectionitoString;
str str
;
return str;
import java.ioBufferedReader;
import java.ioFileReader;
import java.util.Scanner;
public class ProgTwo
public static void mainString args
ProductCollection collection new ProductCollection;
try
BufferedReader reader new BufferedReadernew FileReaderC:UsersSHANOOBDesktopproducttxt;
String line reader.readLine;
while line null
String arr line.split;
collection.addProductIntegerparseIntarr arr Double.parseDoublearr Integer.parseIntarr;
line reader.readLine;
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
