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.
- Open the Product project in Chapter 4
- Open the StockManager class and add your name as author
- Exercise 4.36 - finish the printProductDetails method
- Exercise 4.37 - write the findProduct method. Use a while loop that allows the search to be terminated when the product is found.
- Exercise 4.38 - finish the numberInStock method. Invoke the internal findProduct method.
- Exercise 4.39 - finish the delivery method. Invoke the internal findProduct method.
- implement a void reorder (int quantity) method to print details of all products with stock values lower than the integer passed as a parameter.
- 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
- instantiate a StockDemo
- invoke the demo( ) method
- invoke the sellProduct() with 132 as the parameter
- invoke the sellProduct() with 135 as the parameter
- 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)
|