Académique Documents
Professionnel Documents
Culture Documents
Overview
Create an inventory program that can be used for a range of different products (cds,
dvds, software, etc.). For each part, build upon the last part so that both the old and new
requirements are met.
1. Choose a product that lends itself to an inventory (for example, products in your
home, school, or workplace: office supplies; music CDs; DVD movies; or software).
4. Write getter/accessor and setter/mutator methods for each of the four instance
variables.
5. Override the toString() method from the object class that will show a description of
each object that includes the variable values.
6. Create a Java main class called ProductTester that creates and initializes six Product
objects.
a) Two of the Products should be created using the default constructor
b) The other four should be created using values for the arguments
7. From ProductTester, display the product number, the name of the product, the
number of units in stock, and the price of each unit.
Requirements - Part 2 (Solutions: ProductPart2, ProductTesterPart2)
At this point, students may either modify the original ProductTester and Product classes
or create new classes that will add the new functionality from subsequent parts.
1. Modify ProductTester
a) Add a Scanner.
b) Ask the user to input values for the arguments of the two products in 6a from
Part 1.
2. Create a method in the Product class that will calculate the value of the each
inventory item, using the quantity on hand and price.
2. Ask the user to enter the number of products they wish to add. Accept a positive
integer for the number of products, and handle the value of zero.
3. Using a for loop, ask the user to input the values for the items.
4. Use another for loop to display the information one product at a time, including the
item number, the name of the product, the number of units in stock, the price of each
unit, and the value of the inventory of that product.
Topic(s): Modifying programs, adding methods, user interface to test new methods
1. Create two new methods in the Product class, one that will allow the user to add to
the number of units in stock, and one that will allow the user to deduct from the
number of units in stock. Both methods should have a parameter for the number of
items to add/deduct.
2. Modify ProductTester again so that the user can modify the items. Ask the user if
they would like to add or deduct from the inventory for the item as each item is
displayed.
Topic(s): Interfaces - particularly the Comparable Interface for sorting one type of
object, the compareTo() method, Arrays.sort()
1. Implement the Comparable Interface to create another method in the Product class.
Modify ProductTester to use Arrays.sort() to sort the array items by the name of the
product. Redisplay the products.
Topic(s): Adding a subclass, using extends, using super(), overriding methods from a
superclass, using the generic Comparable Interface
1. Create a subclass of the Product class that has two additional variables. (For
example, a DVD subclass could use movie title and length).
2. In the subclass, override the method to calculate the value of the inventory of a
product with the same name as that method previously created for the product class.
The subclass method should also add a 5% restocking fee to the value of the
inventory of that product.
3. Override the toString() method from the Product class so that all information about
new subclass objects can be printed to the output.
4. Modify ProductTester so that an array of objects of the new subclass can be created
from user input. Display the subclass products using a for loop.
6. Modify ProductTester to sort the array items by the title of the DVD. Redisplay the
products.