Question: Java Object Oriented Programming Choose a type of product to sell (food, apparel, electronics, cosmetics, housewares, etc.). Create a program which loads 4 parallel arrays
Java Object Oriented Programming
Choose a type of product to sell (food, apparel, electronics, cosmetics, housewares, etc.). Create a program which loads 4 parallel arrays with 20 items each. Use your own data. Do not replicate data which I post, nor use data from another student. Make at least 4 categories, for example, if you were categorizing animals, then you would use M for mammal, R for reptile, F for fish, and B for bird. Store the following 4 parallel arrays in main(). Populate them with data using initializer lists.
String [] productName
double [] productPrice
int [] productQuantity
char [] productCategory
Part 1: Create the following functions:
1. void displayReport(String [] pn, double [] pp, int [] pq, char [] pc) which will have a report format with headers, detail line and footers as follows (note that widths are suggested with printf format specifiers):
Product (%20s) Price (%10.2f) Qty (%10d) Category(10s) Ext. Price (%10.2f)
xxxxxxxxxxxxxxxxxxxx 9999999.99 9999999999 xxxxxxxxxx 9999999.99
Average Sales: 9999999.99 // NOTE: This is generated by findTotalSales()
Total Sales: 9999999.99 // NOTE: This is generated by findAverageSales()
2. double findTotalSales(double [] pp, int [] pq)
3. double findAverageSales(double [] pp, int [] pq)
4. void productDetailLine(), productHeader(), and productFooter() functions to generate parts of the reports.
5. void changeQuantity() search for a product and change the quantity for that product in the array. This will require that the user enter a value (use Scanner here), then search, and enter another value to replace that with.
6. void changePrice() - search for a product and change the price for that product in the array. Similar input to #5.
7. void categoryReport(char c) send any category to this function to generate a report
8. void priceReport(double p) send a max price to this function to generate a report
9. void sortByNameReport(String [] pn, double [] pp, int [] pq) uses a bubble sort and an index sorting algorithm
10. void sortByPriceReport() similar to #9
Output: Show all reporting function output including displayReport(), priceReport(), categoryReport() and sortByNameReport(), sortByPriceReport().
Part 2: Two functions that deal with the data as an object, stored to an ArrayList of objects. For this part, create a class in your project called Product which stores as member variables, productName, productPrice, productQuantity, and productCategory. You may use public members here to avoid all the accessors/mutators.
11. Product findProduct(String p)
12. Product getObject(String [] pn, double [] pp, int [] pq)
In main(), store the entire set of arrays into an ArrayList of objects using the Player class and a function such as:
ArrayList convertArraysToArrayList(String [] pn, double [] pp, int [] pq)
Note: The ArrayList is created in the function from the data passed in the 4 arrays, then encapsulated into an object and added to the ArrayList. Arrays and ArrayLists are pass by reference.
Output: More info to come for Week 10. Part 2 may slightly change for Week 10
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
