Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is StockManger Class: import java.util.ArrayList; public class StockManager { // A list of the products. private ArrayList stock; /** * Initialise the stock manager.

image text in transcribed

This is StockManger Class:

import java.util.ArrayList;

public class StockManager { // A list of the products. private ArrayList stock;

/** * Initialise the stock manager. */ public StockManager() { stock = new ArrayList(); }

/** * Add a product to the list. * @param item The item to be added. */ public void addProduct(Product item) { stock.add(item); } /** * Receive a delivery of a particular product. * Increase the quantity of the product by the given amount. * @param id The ID of the product. * @param amount The amount to increase the quantity by. */ public void delivery(int id, int amount) { } /** * Try to find a product in the stock with the given id. * @return The identified product, or null if there is none * with a matching ID. */ public Product findProduct(int id) { return null; } /** * Locate a product with the given ID, and return how * many of this item are in stock. If the ID does not * match any product, return zero. * @param id The ID of the product. * @return The quantity of the given product in stock. */ public int numberInStock(int id) { return 0; }

/** * Print details of all the products. */ public void printProductDetails() { } }

A company records stock levels of the products it sells. A Stock Manager object maintains an arbitrary-length list of Product objects. Your task is to complete the outline implementation of the StockManger class. The StockDemo class has been provided to help demonstrate ways in which StockManager and Product objects might be used. You can create a StockDemo object on the object bench and call its demo method. As you develop the Stock Manager class, this demo should demonstrate increasing functionality. The StockManager Class The Stock Manager class uses a LinkedList object to store zero or more Product items. Its addProduct method adds a new product to the collection. The following methods need completing: delivery, findProduct, printProductDetails, and numberInStock. The delivery method should find the Product with the given ID in the list of products and then call its increase Quantity method. The find Product method should look through the collection for a product whose id field matches the id argument of this method. If a matching product is found, that Product should be returned as the method's result. If no matching product is found, return null from the method. The printProductDetails method should iterate over the list of products and print the result of calling the toString() method on each. The numberInStock method should locate a product in the collection with a matching ID, and return the current quantity of that product as a method result. If no product with a matching ID is found, return zero

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

101 Database Exercises Text Workbook

Authors: McGraw-Hill

2nd Edition

0028007484, 978-0028007489

More Books

Students also viewed these Databases questions