Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part II - The Inventory Reporting Program Once you have coded and tested your Product class, you will need to write the inventory reporting program.

Part II - The Inventory Reporting Program

Once you have coded and tested your Product class, you will need to write the inventory reporting program. You must read each product into a single Product object and maintain an ArrayList of Product objects. In addition, the format of the output report will be slightly more complex. For the inventory reporting program, create a new Java class named OOPReport.java. Note that part of this assignment is determining how you should break your code down into methods. You will not be given the methods to use but instead must determine what methods should be used for this project. DO NOT submit a monolithic solution where all of your code is in the main method. Monolithic solutions will receive at best a maximum score of 6 points, regardless of correctness of output. Before beginning to code, think carefully about how the actions being taken by this program can be broken down into subroutines rather than monolithic operations. Here is a sample transcript of the output of this program - user inputs are in BOLD:

Enter an inventory filename: input.txt Product Inventory Summary Report --------------------------------------------------------------------------- Product Name I Code Type Rating # Rat. Quant. Price ------------------------- --------- ---- ------ ------ ------ ------ The Shawshank Redemption C0000001 DVD *** 4 100 19.95 The Dark Knight C0000003 DVD *** 3 50 19.95 Casablanca C0000007 DVD **** 4 137 9.95 The Girl With The Dragon C0000015 Book *** 3 150 14.95 Vertigo C0000023 DVD **** 6 55 9.95 A Game of Thrones C0000019 Book 0 100 8.95 --------------------------------------------------------------------------- Total products in database: 6 Highest Average Ranked item: Casablanca (****) Lowest Average Ranked item: A Game of Thrones () Highest Total Dollar item: The Girl With The Dragon Tattoo ($2,242.50) Lowest Total Dollar item: Vertigo ($547.25) --------------------------------------------------------------------------- 

The program should perform the following actions:

  1. Prompt the user for the name of a file that contains the inventory database (see below for the format of this file).
  2. Input the inventory information and store it in a single ArrayList of Product objects
  3. Print out a well formatted line of information summarizing each product. The average user rating for each product should be presented as a number of stars from 0 to 5, depending on what the average rating is for the product. "# Rat." indicates the total number of ratings a particular product has. Your report should be presented with columns lining up appropriately as displayed above. One way to manage this is by using Java's format strings - see section 7.2.9 in the textbook, or the Java Tutorial documentation on format strings. (Links to an external site.) However you accomplish it, keep in mind that your code MUST work for different input files in the same format that might have different values for the columns.
  4. Find the:
  • Item with the highest average user rating in stock
  • Item with the lowest average user rating in stock
  • Item with the largest total dollar amount in inventory (quantity * price)
  • Item with the smallest total dollar amount in inventory (quantity * price)
  • Output a well-formatted report as decribed above. Note that when the items with the highest/lowest user rating are displayed, their user rating should be presented as a number of stars from 0 to 5, and when the items with the highest/lowest total dollar amount are displayed, their dollar amounts should be shown in parentheses next to the title. In the case where there is a "tie" between items for any of these rankings, any selection is a valid one.

NOTE: The Product class stores price as an integer value in pennies. The report displays the price in dollars and cents. You should be able to manage this WITHOUT converting the integer value to a String and using substrings. HINT: Think about using the integer division (/) and remainder (%) operators to carve up the number into dollars and cents.

Input File Format

The input file for this assignment uses the following format:

[product 1 name] [product 1 item code] [product 1 quantity] [product 1 price] [product 1 type] [product 1 user ranking 1] ... -1 ... [product n name] [product n item code] [product n quantity] [product n price] [product n type] [product 1 user ranking 1] ... -1 Quantity will always be an integer value, price will always be an integer value in pennies. Name, type and item code will always be a String. User ratings will be a number that should be between 0 and 5. Note that you will not know in advance how many user ratings there will be, but we will guarantee that after the last user rating there will be a negative number before the next product starts. The file will always end with a negative number as the last line. A sample text file for the above transcript might look like this: The Shawshank Redemption C0000001 100 1995 DVD 4 5 3 1 -1 The Dark Knight C0000003 50 1995 DVD 5 2 3 -1 Casablanca C0000007 137 995 DVD 5 4 5 3 -1 The Girl With The Dragon Tattoo C0000015 150 1495 Book 4 4 2 -1 Vertigo C0000023 55 995 DVD 5 5 3 5 2 4 -1 A Game of Thrones C0000019 100 895 Book -1 Note that you may assume that the file will be correctly formatted, however your code must work properly whether or not there is a blank line at the end of the input file. Create a few different test files to verify that your code works properly for different inputs. Note also that we are not giving you the number of elements that will be in the file, so you should not use arrays to solve this problem - make sure your code uses ArrayLists to store and manipulate the data.

PRODUCT CLASS.JAVA:

public class Product {

// Private member variables go here - you will need to add them yourself.

/** * Product constructor - creates a default product with no name or type and * a price of 0. */ public Product() {

}

/** * sets the name of the product object * * @param name * - new name for the product */ public void setName(String name) {

}

/** * returns the name of the product * * @return the name of the product */ public String getName() { return ""; }

/** * sets the type of the product * * @param type * - the type of the product */ public void setType(String type) {

}

/** * returns the type of the product * * @return - the product type */ public String getType() { return ""; }

/** * sets the price of the product in cents. A $10 product will have a price * of 1000. * * @param price * - the price of the product */ public void setPrice(int price) {

}

/** * returns the price of the product in cents. * * @return the price of the product */ public int getPrice() { return 0; }

/** * sets the count of this product in our inventory. * * @param quantity * - the number of this product in inventory */ public void setQuantity(int quantity) {

}

/** * returns the count of this product in our inventory * * @return the number of this product in inventory */ public int getQuantity() { return 0; }

/** * sets the inventory code for this product * * @param code * - the new inventory code for the product */ public void setInventoryCode(String code) {

}

/** * returns the inventory code for this product * * @return the inventory code of the product */ public String getInventoryCode() { return ""; }

/** * NOTE: Each individual rating is stored with the product, so you need to * maintain a list of user ratings. This method should append a new rating * to the end of that list * * @param rating * - the new rating to add to this product */ public void addUserRating(int rating) {

}

/** * NOTE: See note on addUserRating above. This method should be written to * allow you to access an individual value from the list of user ratings * * @param index * - the index of the rating we want to see * * @return the rating indexed by the value index */ public int getUserRating(int index) { return 0; }

/** * NOTE: See note on addUserRating above. This method should be written to * return the total number of ratings this product has associated with it * * @return the number of ratings associated with this product */ public int getUserRatingCount() { return 0; }

/** * NOTE: see note on addUserRating above. This method should be written to * compute the average user rating on demand from a stored list of ratings. * * @return the average rating for this product as a whole integer value (use * integer math) */ public int getAvgUserRating() { return 0; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions