Home‎ > ‎ICT Programming‎ > ‎Java‎ > ‎

The Product Project

The Product Project

Download and open the product-project.

Activity 1

  • Create an instance of the StockDemo class. This demo shows how the product-project works. The instance contains three products with product numbers 132, 37 and 32.
  • Invoke each of the StockDemo class' methods: getProduct, sellProduct and showDetails. Use any of the three product numbers when you test these methods. What happens if you use other numbers as the product number?

Each product sold by the company is represented by an instance of the Product class which records a product's ID, name and how many of that product is currently in stock.

Activity 2

  • Create an instance of the Product class. Use any name and product number you'd like.
  • Invoke each of the three accessor methods of this class.
  • Invoke the toString method.
  • Invoke the increaseQuantity method and add 30 items to the inventory. Then invoke getQuantity again.
  • Invoke the sellOne method and once again invoke getQuantity.

You should now be familiar with the methods of the Product class. The StockManager class uses an ArraysList to store Product items. Its addProduct method is complete, but the other methods in this class need to be implemented.

Complete the following exercises in the StockManager class:

  1. Implement the printProductDetails method that will display the details of all products in the collection. Use the toString method of the Product class.
  2. Implement the findProduct method. this method This method should look through the products in the collection to find one whose product ID matches the method's parameter. It will return the matching Product or, if no match is found, it will return null.
  3. Implement the numberInStock method. This method should locate the product in the collection whose ID matches the method's parameter and then return the number of items in stock. Return 0 if the parameter value does not match any product number in the collection. Hint: use the findProduct method in exercise 2.
  4. Implement the delivery method. This method is used when the store receives a delivery from its supplier. It should locate the product that matches the parameter and then add the second parameter to that product's quantity.
  5. Modify the addProduct method so that a new product can not be added to the product list with the same ID as an existing one.
  6. Add a method called findProduct that will find a product by its name rather than its ID number. It should return the product in the product list whose name matches the parameter, or null if none do.
  7. Add a new method called inventory that will return the total number of items in the company's entire inventory.
Comments