This quiestions involves GroceryChains which store a list of GroceryStore objects. You are to complete the following tasks. /** * A class for a grocery store. Complete the following tasks: * * - Implement a constructor that takes in initial values for each item type * - Add a method that adds inventory of a given type * - Add a method that returns the inventory of a given type */ public class GroceryStore { // A set of possible items at the grocery store public enum GroceryItem {LETTUCE, TOMATO, CUCUMBER} private int lettuceInventory; private int tomatoInventory; private int cucumberInventory; private String name; // Implement a grocery store constructor which takes in a store name, and initial // amounts for each of the inventory types public GroceryStore(String name, int lettuce, int tomato, int cucumber) { //-----------Start below here. To do: approximate lines of code = 4 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } // Adds the given amount of the given type to the given inventory // You can assume the given amount is always non-negative public void addInventory(GroceryItem type, int amount) { //-----------Start below here. To do: approximate lines of code = 6 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } // Gets the inventory of the given type public int getInventory(GroceryItem type) { //-----------Start below here. To do: approximate lines of code = 7 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } } ______________________________________________________ import java.util.ArrayList; /** * A class for a grocery chain which stores an array list of stores. * * - Add the constructor * - Add a method that adds a grocery store to the chain * - Implement the getTotalInventory method */ public class GroceryChain { private ArrayList stores; private String name; // Add a constructor which takes in a name for the grocery chain and // initializes ArrayList //-----------Start below here. To do: approximate lines of code = 3 //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. // Create a method called addGroceryStore which takes in a GroceryStore // and adds it to the ArrayList //-----------Start below here. To do: approximate lines of code = 2 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. // Calculate the total inventory of the given item over all stores // in the ArrayList public int getTotalInventory(GroceryStore.GroceryItem type) { //-----------Start below here. To do: approximate lines of code = 4 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } } _________________________________________ public class GroceryTester { public static void main(String[] args) { GroceryStore store1 = new GroceryStore("MLG Loblaws", 40, 150, 75); GroceryStore store2 = new GroceryStore("Dundas Square Loblaws", 30, 100, 50); GroceryStore store3 = new GroceryStore("West End Loblaws", 50, 80, 60); // Tests get inventory method System.out.println("The inventory of tomato at MLG Loblaws is " + store1.getInventory(GroceryStore.GroceryItem.TOMATO)); System.out.println("Expected:\nThe inventory of tomato at MLG Loblaws is 150"); System.out.println("The inventory of lettuce at Dundas Square Loblaws is " + store2.getInventory(GroceryStore.GroceryItem.LETTUCE)); System.out.println("Expected:\nThe inventory of lettuce at Dundas Square Loblaws is 30"); System.out.println("The inventory of cucumber at West End Loblaws is " + store3.getInventory(GroceryStore.GroceryItem.CUCUMBER)); System.out.println("Expected:\nThe inventory of cucumber at West End Loblaws is 60"); // Tests the add inventory method store1.addInventory(GroceryStore.GroceryItem.TOMATO, 10); System.out.println("The inventory of tomato at MLG Loblaws is " + store1.getInventory(GroceryStore.GroceryItem.TOMATO)); System.out.println("Expected:\nThe inventory of tomato at MLG Loblaws is 160"); store3.addInventory(GroceryStore.GroceryItem.CUCUMBER, 10); System.out.println("The inventory of cucumber at West End Loblaws is " + store3.getInventory(GroceryStore.GroceryItem.CUCUMBER)); System.out.println("Expected:\nThe inventory of cucumber at West End Loblaws is 70"); // Creates stores GroceryChain loblaws = new GroceryChain("loblaws"); loblaws.addGroceryStore(store1); loblaws.addGroceryStore(store2); loblaws.addGroceryStore(store3); // Tests the getTotalInventory method System.out.println("The total inventory of lettuce is " + loblaws.getTotalInventory(GroceryStore.GroceryItem.LETTUCE)); System.out.println("Expected:\nThe total inventory of lettuce is 120");

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

This quiestions involves GroceryChains which store a list of GroceryStore objects. You are to complete the following tasks. /** * A class for a grocery store. Complete the following tasks: * * - Implement a constructor that takes in initial values for each item type * - Add a method that adds inventory of a given type * - Add a method that returns the inventory of a given type */ public class GroceryStore { // A set of possible items at the grocery store public enum GroceryItem {LETTUCE, TOMATO, CUCUMBER} private int lettuceInventory; private int tomatoInventory; private int cucumberInventory; private String name; // Implement a grocery store constructor which takes in a store name, and initial // amounts for each of the inventory types public GroceryStore(String name, int lettuce, int tomato, int cucumber) { //-----------Start below here. To do: approximate lines of code = 4 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } // Adds the given amount of the given type to the given inventory // You can assume the given amount is always non-negative public void addInventory(GroceryItem type, int amount) { //-----------Start below here. To do: approximate lines of code = 6 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } // Gets the inventory of the given type public int getInventory(GroceryItem type) { //-----------Start below here. To do: approximate lines of code = 7 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } }

______________________________________________________

import java.util.ArrayList; /** * A class for a grocery chain which stores an array list of stores. * * - Add the constructor * - Add a method that adds a grocery store to the chain * - Implement the getTotalInventory method */ public class GroceryChain { private ArrayList<GroceryStore> stores; private String name; // Add a constructor which takes in a name for the grocery chain and // initializes ArrayList //-----------Start below here. To do: approximate lines of code = 3 //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. // Create a method called addGroceryStore which takes in a GroceryStore // and adds it to the ArrayList //-----------Start below here. To do: approximate lines of code = 2 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. // Calculate the total inventory of the given item over all stores // in the ArrayList public int getTotalInventory(GroceryStore.GroceryItem type) { //-----------Start below here. To do: approximate lines of code = 4 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } }

_________________________________________

public class GroceryTester { public static void main(String[] args) { GroceryStore store1 = new GroceryStore("MLG Loblaws", 40, 150, 75); GroceryStore store2 = new GroceryStore("Dundas Square Loblaws", 30, 100, 50); GroceryStore store3 = new GroceryStore("West End Loblaws", 50, 80, 60); // Tests get inventory method System.out.println("The inventory of tomato at MLG Loblaws is " + store1.getInventory(GroceryStore.GroceryItem.TOMATO)); System.out.println("Expected:\nThe inventory of tomato at MLG Loblaws is 150"); System.out.println("The inventory of lettuce at Dundas Square Loblaws is " + store2.getInventory(GroceryStore.GroceryItem.LETTUCE)); System.out.println("Expected:\nThe inventory of lettuce at Dundas Square Loblaws is 30"); System.out.println("The inventory of cucumber at West End Loblaws is " + store3.getInventory(GroceryStore.GroceryItem.CUCUMBER)); System.out.println("Expected:\nThe inventory of cucumber at West End Loblaws is 60"); // Tests the add inventory method store1.addInventory(GroceryStore.GroceryItem.TOMATO, 10); System.out.println("The inventory of tomato at MLG Loblaws is " + store1.getInventory(GroceryStore.GroceryItem.TOMATO)); System.out.println("Expected:\nThe inventory of tomato at MLG Loblaws is 160"); store3.addInventory(GroceryStore.GroceryItem.CUCUMBER, 10); System.out.println("The inventory of cucumber at West End Loblaws is " + store3.getInventory(GroceryStore.GroceryItem.CUCUMBER)); System.out.println("Expected:\nThe inventory of cucumber at West End Loblaws is 70"); // Creates stores GroceryChain loblaws = new GroceryChain("loblaws"); loblaws.addGroceryStore(store1); loblaws.addGroceryStore(store2); loblaws.addGroceryStore(store3); // Tests the getTotalInventory method System.out.println("The total inventory of lettuce is " + loblaws.getTotalInventory(GroceryStore.GroceryItem.LETTUCE)); System.out.println("Expected:\nThe total inventory of lettuce is 120");

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education