Вы находитесь на странице: 1из 3

FYI: 1. YOU WILL BE GRADED ACCORDING TO THE CORRECTNESS OF YOUR OUTPUT AND YOUR COMPLIANCE TO THESE SPECIFICATIONS. 2.

NO COPY PASTE; IF CAUGHT YOU AND THE SOURCE WILL BE GRADED 5.00 Grocery Store Line Simulator Create a Java application that simulates the operations that happen in a grocery store. The application should be able to trace what happens whenever products in the grocery are sold. Cash registers facilitate the sales of these products. Sales are recorded on a per-customer basis. A cashier scans each product to be bought by a customer. For each product, a quantity is specified, the price of that particular product is checked, and then the purchase price is computed and added to the total bill. The inventories of the products in the grocery are also updated as they are purchased. At the end of the day, two reports are generated. The first is a report listing the summary of transactions for each cash register, and the second is a report on the remaining inventory for each product. In a real grocery setting, a customer would typically provide payment at the end of a purchasehowever, to make this assignment simpler; we will assume that cash is provided at the beginning of the purchase. This way, the application can prevent products from being bought if there is not enough cash left. In effect, an attempt to buy is denied if one of two cases occurs: there is not enough stock for the product, or the customer does not have enough money. We will assume that only three products are sold in this simple grocery and that they are called apples, oranges, and pomelos. Set the price and initial inventory of these products to the following values: "apples": 15.75 pesos, 50 items oranges: 12.50 pesos, 80 items "pomelos": 95.25 pesos, 25 items

You will develop three Java classes that interact with each other: Cashier, PriceAndStockManager, and Product. Cashier objects are in charge of front-office operations, particularly purchases. These cashiers use a PriceAndStockManagerobject in charge of back office operations. This object provides the price of each product bought and updates the product inventories. Inside the PriceAndStockManager object, Product objects are managed and it is through these objects that prices are obtained and inventories are updated. The product objects are created when PriceAndStockManager is instantiated. A Store class will be provided that tests all these classes that you will create, although we recommend that you test the Cashier, PriceAndStockManager, and Product classes visually through the BlueJ environment. You are required to have the following methods in the Cashier class: public void startPurchase( double money ): - This method signals the start of a purchase transaction. The parameter, money, tells us how much the money the customer has at the beginning of the purchase.

Computer Programming 4 Case Study

Page 1 //evf

public void buy( String productName, intqty ): - This method causes qtyitems of the product named productNameto be bought. It also checks for errors, such as supplying a negative value for qty, not enough cash, and not enough stock (if the product name supplied is not any of the 3 products, just indicate that there is not enough stock). If a product has been successfully purchased, the amount is added to the current bill. public void endPurchase(): - This signals the end of a purchase transaction. It prints out a message summarizing the transaction including the total bill and change returned. public void printSalesSummary(): - This method prints out a running summary (typically called when the store closes). The summary contains the number of customers served and the cash collection. In the Cashier class, you will need fields that keep track of total sales so far, the bill amount and the available cash for the current customer, and the total number of customers so far. Note that the constructor for Cashier will include a PriceAndStockManager object and that the Cashier class will need to call methods on this object. The PriceAndStockManagerclass will have methods that return the price of a product given a product name, find out if there is enough stock for a product given a product name, and carry out a product purchase. You may name these methods in any way you wish. However, you need to include a method called printInventoryReport() that lists the inventory for each product. The class will of course need to define and create Product objects and call methods on such objects. The Product class will need to store price and stock level information. The methods for this class are all up to you. Test your project by creating a single PriceAndStockManager object, and then several Cashier objects associated with this single manager object. Carry out transactions through the different cashiers. When finished, call the printSalesSummary() method on each cashier and the printInventoryReport() method on the manager object to see if the values printed are correct. Grocery Store Simulation II Create a Java application that builds on Grocery Store Line Simulator. This project still simulates the operations that happen in a grocery store. The project is an exercise in arrays and ArrayList objects. This time, you will support additional features, over and above what is currently supported in Grocery Store Line Simulator. Theadditional features are: - the addition of new products in the grocery - support for an arbitrary number of cashiers - delivery of stock There will be four interacting classes for this project: Grocery, Cashier,PriceAndStockManager, and Product. The last three classes serve the samepurpose as in Grocery Store Line Simulator. Grocery is an aggregate/manager class thatcontains Cashier objects and a PriceAndStockManager object. All transactionswill now be carried out through a Grocery object. Refer to the following diagram.
Computer Programming 4 Case Study Page 2 //evf

Grocery is expected to have an array or an ArrayList of Cashier objects. Theconstructor of Grocery should have an integer parameter N that indicates thenumber of cashiers that will be created. PriceAndStockManager should, asbefore, manage Product objects, although, this time, it will contain either an arrayor an ArrayList of Product objects. The Grocery class is required to have the following methods: - public void startPurchase( intcashierNum, double money ) - public void buy( intcashierNum, String productName, intqty ) - public void endPurchase( intcashierNum ) - public void printSalesSummary() - public void addNewProduct( String productName, double price, intinitStock ) - public void addStock( String productName, intqty ) - public void printInventoryReport() ublic The first three methods should ultimately call the corresponding methods on theappropriate Cashier object. For these methods, the cashierNumparameter, is anumber between 0 and N -1, where N is the number of cashiers in the Grocery(indicated in the constructor). The parameter indicates which cashier e thetransaction is being carried out for. The printSalesSummary() method will causereports to be printed for all cashiers (this method will contain a for for-statement thatcalls printSalesSummary() for each of the tSalesSummary() Cashier objects). The last threemethods indicated above should call corresponding methods on the PriceAndStockManager object.In Grocery Store Line Simulator, the grocery started with three products. Simulator, For this, startwith no productsproducts will be introduced/added through theaddNewProduct() products method, while stock for a given product will be replenishedthrough the addStock() method. A GrocerySimulation program that tests your project will be provided and postedin the course we website. It will contain code that creates a single Grocery object,and then carry out transactions through the above methods.

Computer Programming 4 Case Study

Page 3 //evf

Вам также может понравиться