What to do: Create a project consisting of three classes. These three classes are named ProgTwo.java, Product.java and P

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

What to do: Create a project consisting of three classes. These three classes are named ProgTwo.java, Product.java and P

Post by answerhappygod »

What to do:
Create a project consisting of three classes. These threeclasses are named ProgTwo.java, Product.java andProductCollection.java. You must have these three classes and theymust work as it is described in these specifications. You arewelcome to add methods to any class that you may find useful.You must add commentsto allyour classes, using the javadoc stylecommenting modeled in class. You may add other classes if youconsider them necessary.
How to
turn in
your homework?
This assignment requires you to implement at least threeclasses. The first class, Product, models a basic Product objectfor record keeping of the product's data on a daily basis. Thesecond class ProductCollection, implements methods for storing andmaintaining a single dimension array of Product objects. The thirdclass ProgTwo has a main method which creates and manipulatesProduct objects and stores/retrieves the Products from an arraystructure.
Your program must be developed following the guidelinespreviously discussed in class. These guidelines include appropriatevariable names, use of comments to describe the purpose of theprogram and the purpose of each method, and proper use ofindentation of all program statements.
Product.java details:
One Constructor
Constructor #1. It will take all the parameters as listed:
int idNum
String name
double priceint quantity
Instance variables for the Product class
int idNum
String name
double priceint quantity
Methods that must be part of the Product class (you may andprobably will add other methods):
Method
Functionality
public int getID()
Returns the Product’s ID number.
public void setID(int sID)
Updates the Product’s 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 Product’s price.
public void setPrice(double newPrice)
Updates the Product’s 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 ProductCollectionclass
Product[] collection
int count
Methods that must be part of the ProductCollection class (youmay 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 anew product – if not calls the increaseSize method. Activates theconstructor of the Product class to put the new product object inthe next compartment of the array. Increments the count variable tomaintain 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. Setscollection to point to the new array.
public int indexOf(int prodID)
Returns the index into the collection array where the product IDwas 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 idnumber “prodID” to “newPrice.”
public void buyProduct(int prodID, int qty)
Changes the quantity of the product in the array having the idnumber “prodID” by adding “qty” to it.
public void sellProduct(int prodID, int qty)
Changes the quantity of the product in the array having the idnumber “prodID” by subtracting “qty” from it.
Public void deleteProduct(int prodID)
Removes the product from the array, by shifting all productsbelow it up one compartment and subtracting one from the variablenamed, 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 textfile. Each line contains data about one product in the array witheach 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 andactivates the toString method of the Product class to addinformation 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 filenamed product.txt. This should be read into the array of products.The product.txt file is delimited by commas. After the array iscreated a loop is entered. The loop should display a menu which hasthe following options, obtain the number of the type of transactionfrom the user, and process the transaction. The loop shouldcontinue to execute until the "8" Exit option is selected from themenu. When the exit option is selected, the program should writeout to a text file information about all the products in the arrayin the same format as the input file. The name of the output textfile should be productUpdate.txt.
1. Add Product
Prompt the user to enter the data required for a new product andadd 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 bedeleted. If so, delete the product by moving all of the productsbelow it in the array up one compartment and subtract one fromcount. Display an informative message to the user regarding theaction taken.
3. Change Price
Have the user enter the product ID and the new price of theproduct. Change the price of the product in the array if it exists,otherwise display an informative message to the user that theproduct does not exist.
4. Purchase Product Units
Have the user enter the product ID and quantity of the productpurchased. Adjust the quantity to reflect the purchase of products.Display a message for the user if the product does not exist in thearray.
5. Sell Product Units
Have the user enter the product ID and quantity of the productto be sold. Adjust the quantity to reflect the sale of products.Display a message for the user if the product does not exist in thearray.
6. Display information about an individualproduct
Have the user enter the ID number of the product to bedisplayed. Display the information if the product exists, otherwisedisplay an information message.
7. Display information about all theproducts
List all the products in inventory by using the toString( )method.
8. Exit
This will end the program execution.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply