Question: Code the second class ProductCollection, implements methods for storing and maintaining a single dimension array of Product objects. ProductCollection.java details: One Constructor which has no

Code the second class ProductCollection, implements methods for storing and maintaining a single dimension array of Product objects. ProductCollection.java details: One Constructor which has no parameters. Instance variables for the ProductCollection class Product[] collection int count Methods that must be part of the ProductCollection class (you may add other methods): Method Functionality public void addProduct(int prodID, String prodName, double unitPrice, int prodQty) Checks to determine if there is enough room in the array for a new product if not calls the increaseSize method. Activates the constructor of the Product class to put the new product object in the next compartment of the array. Increments the count variable to maintain an active count of products in the array. public void increaseSize() Creates a new array which is twice as big as the current array. Copies elements from the current array into the new array. Sets collection to point to the new array. public int indexOf(int prodID) Returns the index into the collection array where the product ID was found. Returns -1 if the product is not in the array. public void changePrice(int prodID, double newPrice) Changes the price of the product in the array having the id number prodID to newPrice. public void buyProduct(int prodID, int qty) Changes the quantity of the product in the array having the id number prodID by adding qty to it. public void sellProduct(int prodID, int qty) Changes the quantity of the product in the array having the id number prodID by subtracting qty from it. Public void deleteProduct(int prodID) Removes the product from the array, by shifting all products below it up one compartment and subtracting one from the variable named, count. public void displayProduct(int prodID) Displays the product have the id number prodID. public String createOutputFile() Creates an output file in the same format as the input text file. Each line contains data about one product in the array with each field being separated by a comma. The line is in the form: ID,Name,Price,Quantity, public String toString() Creates a nicely formatted heading for a report of products and activates the toString method of the Product class to add information about each product to one line of the report.
PLEASE MAKE SURE THE CODE IS WORKING AND TEST IT TO SEE IF IT WORKS OR NOT

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!