What to do: Create a project consisting of three classes. These three classes are named ProgTwo.java, Product.java and ProductCollection.java. You must have these three classes and they must work as it is described in these specifications. You are welcome to add methods to any class that you may find useful. You must add comments to all your classes, using the javadoc style commenting modeled in class. You may add other classes if you consider them necessary.

This assignment requires you to implement at least three classes. The first class, Product, models a basic Product object for record keeping of the product's data on a daily basis. The second class ProductCollection, implements methods for storing and maintaining a single dimension array of Product objects. The third class ProgTwo has a main method which creates and manipulates Product objects and stores/retrieves the Products from an array structure.

Your program must be developed following the guidelines previously discussed in class. These guidelines include appropriate variable names, use of comments to describe the purpose of the program and the purpose of each method, and proper use of indentation of all program statements.

Product.java details:

One Constructor

Constructor #1. It will take all the parameters as listed:

int idNum
String name
double price
int quantity

Instance variables for the Product class

int idNum
String name
double price
int quantity

Methods that must be part of the Product class (you may and probably will add other methods):

  • public int getID() Returns the Products ID number.
  • public void setID(int sID) Updates the Products ID number.
  • public String getName( ) Returns the Product's name.
  • public void setName(String sName) Updates the Product's name.
  • public double getPrice( ) Returns the Products price.
  • public void setPrice(double newPrice) Updates the Products price.
  • public int getQuantity( ) Returns the quantity in inventory.
  • public void setQuantity(int newQuantity ) Updates the quantity in inventory.
  • public String toString( ) Returns a printable version of the Product Object.

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):

  • 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.

ProgTwo.java technical specifications:

ProgTwo should manage a array of product objects. Initial data about products is available in a text file named product.txt. This should be read into the array of products. The product.txt file is delimited by commas. After the array is created a loop is entered. The loop should display a menu which has the following options, obtain the number of the type of transaction from the user, and process the transaction. The loop should continue to execute until the "8" Exit option is selected from the menu. When the exit option is selected, the program should write out to a text file information about all the products in the array in the same format as the input file. The name of the output text file should be productUpdate.txt.

1. Add Product Prompt the user to enter the data required for a new product and add the product into the array of products.

2. Delete Product Have the user enter the product ID. If the product exists, prompt the user to confirm that they want the product to be deleted. If so, delete the product by moving all of the products below it in the array up one compartment and subtract one from count. Display an informative message to the user regarding the action taken.

3. Change Price Have the user enter the product ID and the new price of the product. Change the price of the product in the array if it exists, otherwise display an informative message to the user that the product does not exist.

4. Purchase Product Units Have the user enter the product ID and quantity of the product purchased. Adjust the quantity to reflect the purchase of products. Display a message for the user if the product does not exist in the array.

5. Sell Product Units Have the user enter the product ID and quantity of the product to be sold. Adjust the quantity to reflect the sale of products. Display a message for the user if the product does not exist in the array.

6. Display information about an individual product Have the user enter the ID number of the product to be displayed. Display the information if the product exists, otherwise display an information message.

7. Display information about all the products List all the products in inventory by using the toString( ) method.

8. Exit This will end the program execution.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.