Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. This question involves ordering products from a grocery store. Products sold at the grocery store are represented by the following Product class. public class

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

1. This question involves ordering products from a grocery store. Products sold at the grocery store are represented by the following Product class. public class Product { /** Returns the name of the product */ public String getName() { /* implementation not shown */ } * /** Returns the quantity of the product that is in stock Postcondition: The value returned is greater than or equal to zero. */ public int getQuantity() { /* implementation not shown */ } // There may be instance variables, constructors, and methods that are not shown. } The products available for sale are represented by a Grocerystore object, which contains an array of all products normally stocked at the grocery store. You will write two methods of the GroceryStore class. public class GroceryStore { /** An array of products normally stocked at the grocery store Guaranteed not to be null and to contain only non-null entries * private Product[] productsStocked; /** Returns an ArrayList of indices for Product elements in the productsStocked array that need to be reordered, as described in part (a) Precondition: min > 0 * * public ArrayList getReorderList(int min) { /* to be implemented in part (a) */ > /** Returns true if all products named in shoppingList are available for purchase and returns false otherwise, as described in part (b) Precondition: The products named in shoppingList are found exactly once in the productsStocked array. public boolean checkAvailability(ArrayList shoppingList) { /* to be implemented in part (b) */ } // There may be instance variables, constructors, and methods that are not shown. (a) Write the GroceryStore method getReorderlist. The method returns an ArrayList of Integer objects representing the indices of product elements in the productsStocked array that need to be reordered. Products with quantities less than or equal to min need to be reordered. If there are no products in the productsStocked array that need reordering, the method returns an empty ArrayList. Complete method getReorderList. * /** Returns an ArrayList of indices for Product elements in the productsStocked array that need to be reordered, as described in part (a) Precondition: min > 0 */ public ArrayList getReorderList(int min) (b) Write the GroceryStore method checkAvailability. The method is intended to check whether all items named in a shopping list can be purchased at the grocery store. The method returns true if, for every product name in shoppingList, the product with the same name in the productsStocked array has a quantity greater than or equal to 1. The method returns false if there is any product name in shoppingList for which the quantity of the product with the same name in productsStocked is less than 1. Assume that all products named in shoppingList are found exactly once in the productsStocked array. Complete method checkAvailability. * /** Returns true if all products named in shoppingList are available for purchase and returns false otherwise, as described in part (b) Precondition: The products named in shoppingList are found exactly once in the productsStocked array. * public boolean checkAvailability(ArrayList shoppingList) (c) A programmer would like to add a method called oversized, which returns a list of all products that weigh more than a given amount. Write a description of how you would change the Product and GroceryStore classes in order to support this modification. Make sure to include the following in your response. Write the method header for the oversized method. Identify any new or modified instance variables, constructors, or methods aside from the oversized method. Do not write the program code for this change. Describe, for each new or revised variable, constructor, or method, how it would change or be implemented, including visibility and type. You do not need to describe the implementation of the oversized method. Do not write the program code for this change. . 1. This question involves ordering products from a grocery store. Products sold at the grocery store are represented by the following Product class. public class Product { /** Returns the name of the product */ public String getName() { /* implementation not shown */ } * /** Returns the quantity of the product that is in stock Postcondition: The value returned is greater than or equal to zero. */ public int getQuantity() { /* implementation not shown */ } // There may be instance variables, constructors, and methods that are not shown. } The products available for sale are represented by a Grocerystore object, which contains an array of all products normally stocked at the grocery store. You will write two methods of the GroceryStore class. public class GroceryStore { /** An array of products normally stocked at the grocery store Guaranteed not to be null and to contain only non-null entries * private Product[] productsStocked; /** Returns an ArrayList of indices for Product elements in the productsStocked array that need to be reordered, as described in part (a) Precondition: min > 0 * * public ArrayList getReorderList(int min) { /* to be implemented in part (a) */ > /** Returns true if all products named in shoppingList are available for purchase and returns false otherwise, as described in part (b) Precondition: The products named in shoppingList are found exactly once in the productsStocked array. public boolean checkAvailability(ArrayList shoppingList) { /* to be implemented in part (b) */ } // There may be instance variables, constructors, and methods that are not shown. (a) Write the GroceryStore method getReorderlist. The method returns an ArrayList of Integer objects representing the indices of product elements in the productsStocked array that need to be reordered. Products with quantities less than or equal to min need to be reordered. If there are no products in the productsStocked array that need reordering, the method returns an empty ArrayList. Complete method getReorderList. * /** Returns an ArrayList of indices for Product elements in the productsStocked array that need to be reordered, as described in part (a) Precondition: min > 0 */ public ArrayList getReorderList(int min) (b) Write the GroceryStore method checkAvailability. The method is intended to check whether all items named in a shopping list can be purchased at the grocery store. The method returns true if, for every product name in shoppingList, the product with the same name in the productsStocked array has a quantity greater than or equal to 1. The method returns false if there is any product name in shoppingList for which the quantity of the product with the same name in productsStocked is less than 1. Assume that all products named in shoppingList are found exactly once in the productsStocked array. Complete method checkAvailability. * /** Returns true if all products named in shoppingList are available for purchase and returns false otherwise, as described in part (b) Precondition: The products named in shoppingList are found exactly once in the productsStocked array. * public boolean checkAvailability(ArrayList shoppingList) (c) A programmer would like to add a method called oversized, which returns a list of all products that weigh more than a given amount. Write a description of how you would change the Product and GroceryStore classes in order to support this modification. Make sure to include the following in your response. Write the method header for the oversized method. Identify any new or modified instance variables, constructors, or methods aside from the oversized method. Do not write the program code for this change. Describe, for each new or revised variable, constructor, or method, how it would change or be implemented, including visibility and type. You do not need to describe the implementation of the oversized method. Do not write the program code for this change

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

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago