Scott Grissom
School of Computing & Info Systems
Grand Valley State University
picture

Lab: Ch 4 Stock Manager

Preparation

Do the following before arriving at lab:

  • Read chapter 4.1 - 4.10
  • Bring your textbook to lab

Objectives

After completing this lab, you should be able to:

  • access data from an ArrayList
  • use the for-each and while loop to solve problems

Exercises

Perform each of the following exercises.

  1. Open the Product project in Chapter 4
  2. Open the StockManager class and add your name as author
  3. Exercise 4.36 - finish the printProductDetails method
  4. Exercise 4.37 - write the findProduct method. Use a while loop that allows the search to be terminated when the product is found.
  5. Exercise 4.38 - finish the numberInStock method. Invoke the internal findProduct method.
  6. Exercise 4.39 - finish the delivery method. Invoke the internal findProduct method.
  7. implement a void reorder (int quantity) method to print details of all products with stock values lower than the integer passed as a parameter.
  8. implement a Product findProduct(String name) that searches for a product given a name. Return null if no product is found. Note that Strings should not be compared with the == operator. Instead, Strings have an internal method str1.equals(str2) returns true if the Strings are equal.
Testing StockManager

The project includes a class StockDemo to test the various methods in StockManager

  1. instantiate a StockDemo
  2. invoke the demo( ) method
  3. invoke the sellProduct() with 132 as the parameter
  4. invoke the sellProduct() with 135 as the parameter
  5. Does everything appear to work? What additions can you make to StockDemo to test the additional methods you wrote? (reorder and findProduct)

Grading Criteria

This lab is worth a possible 10 points. Turn in a printout of the source code for StockManager.

  • methods (8 pts)
  • coding style (2 pts)