Question
Overview Price needs to remain as an integer then converted to a double when needed This project is an updated and expanded version of what
Overview Price needs to remain as an integer then converted to a double when needed
This project is an updated and expanded version of what you did in Project 01. As with the first project, you will be reading data from an input file, determining some summary information about the data, and then displaying a summary report. Unlike Project 01, you will be writing this program in using an object-oriented framework. So this project is broken up into two parts. In the first part you will be writing a class to store individual product information. In the second part you will use the class you have written to load information and display the final summary report.
Objectives
-Practice with programming fundamentals
-Review of various Java fundamentals (branching, loops, variables, methods, etc.)
-Review of Java File I/O concepts
-Practice with Java ArrayList concepts
-Practice with object-oriented programming and design
Project 02 Instructions
Create a new Project folder named Project02, then look at the instructions below.
Part I - The Product class
For this project you will need to implement a class to store and retrieve information about products stored in inventory. A skeleton for this class is provided below:
Product.java
public class Product { // Private member variables go here - you will need to add them yourself. /* * Product constructor */ public Product() { } /* * setName * @param name - new name for the product */ public void setName(String name) { } /* * getName * @return the name of the product */ public String getName() { return ""; } /* * setType * @param type - the type of the product */ public void setType(String type) { } /* * getType * @return - the product type */ public String getType() { return ""; } /* * setPrice * @param price - the price of the product */ public void setPrice(double price) { } /* * getPrice * @return the price of the product */ public double getPrice() { return 0.0; } /* * setQuantity * @param quantity - the number of this product in inventory */ public void setQuantity(int quantity) { } /* * getQuantity * @return the number of this product in inventory */ public int getQuantity() { return 0; } /* * setInventoryCode * @param code - the new inventory code for the product */ public void setInventoryCode(String code) { } /* * getInventoryCode * @return the inventory code of the product */ public String getInventoryCode() { return ""; } /* * addUserRating * 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) { } /* * getUserRating * 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; } /* * getUserRatingCount * 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; } /* * getAvgUserRating * 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; } }
Import this skeleton into your Project02 project folder. Your first task is to complete this class so that it can store information about individual products from the text file. Note that the information you are tracking about products is a little bit different than what you tracked in Project 01 - in addition to tracking the name of the product, the type of product, the price and the quantity in inventory, you will also be tracking a unique inventory code for each product in your inventory as well as customer ratings for your inventory. The skeleton given above does not include the private data members for the class - it is up to you to decide how to store these. If you are stuck as to what the various types should be, consider the return types on the methods in the skeleton and how the invididual items are represented in the sample file below. As you are working on your Product class, you should create a program named ProductTest.java in your Project folder. Every time you make a change to your Product class, add one or more tests to the ProductTest.java program to make sure that your Product class works the way that you think it does. For example, if you give the Product class the ability to set the name of a product, your ProductTest program should use the method to set the name and then check to make sure that the name has been set correctly. You should make sure that your code does the right thing for invalid inputs by creating the proper tests to make sure it is working. You will be turning in this ProductTest code that you write, so make sure it is properly commented and includes your name. It is actually okay to put all of your tests into a single main method for this program, but if you think of a good way to group related tests up into methods that's even better.
Part II - The Inventory Reporting Program
Once you have coded and tested your Product class, you will need to write the inventory reporting program. This program is very similar to the program you wrote for Project 01, except that instead of storing product information across multiple ArrayLists, you should 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 Project02.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:
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:
Ask the user to enter the name of a file that contains the inventory database (see below for the format of this file).
Input the inventory information and store it in a single ArrayList of Product objects
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. See section 7.2.9 in the textbook, the Java Tutorial documentation on format strings, or these brief notes I've put together on using the format method.
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.
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 a double value. 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 19.95 DVD 4 5 3 1 -1 The Dark Knight C0000003 50 19.95 DVD 5 2 3 -1 Casablanca C0000007 137 9.95 DVD 5 4 5 3 -1 The Girl With The Dragon Tattoo C0000015 150 14.95 Book 4 4 2 -1 Vertigo C0000023 55 9.95 DVD 5 5 3 5 2 4 -1 A Game of Thrones C0000019 100 8.95 Book -1
Note that you may assume that the fill will be correctly formatted, however your code must work properly whether there is a blank line at the end of the input file or if the input file ends with the last element. Create a few 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.
Enter an inventory filename: input.txt Product Inventory Summary Report Product Name I Code Type Rating # Rat. Quant. Price ------------------------- --------- ---- - - - - - - - - - - ------ ------ * * * *** + * * * *** m * * * **** + m The Shawshank Redemption The Dark Knight Casablanca The Girl With The Dragon Vertigo A Game of Thrones C0000001 DVD C0000003 DVD C0000007 DVD C0000015 Book C0000023 DVD C0000019 Book 100 19.95 50 19.95 137 9.95 150 14.95 55 9.95 100 8.95 * * *** **** o 0 ----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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) ---- Enter an inventory filename: input.txt Product Inventory Summary Report Product Name I Code Type Rating # Rat. Quant. Price ------------------------- --------- ---- - - - - - - - - - - ------ ------ * * * *** + * * * *** m * * * **** + m The Shawshank Redemption The Dark Knight Casablanca The Girl With The Dragon Vertigo A Game of Thrones C0000001 DVD C0000003 DVD C0000007 DVD C0000015 Book C0000023 DVD C0000019 Book 100 19.95 50 19.95 137 9.95 150 14.95 55 9.95 100 8.95 * * *** **** o 0 ----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started