Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Homework 11 Grocery List Objectives Practice data abstraction in class design. Write a class named GroceryList that represents a list of items to be purchased

image text in transcribed
image text in transcribed
Homework 11 Grocery List Objectives Practice data abstraction in class design. Write a class named GroceryList that represents a list of items to be purchased from a grocery store, and another class named GroceryItemorder that represents a purchase item in a given quantity (example: four boxes of cookies). The Grocer List class should use an array to store the grocery items and an integer to keep track of the number of items in the list. Assume that a grocery list will have no more than 10 items. In other words, in the GroceryList class you should define two fields: one is an array that can accommodate 10 items and the other is an integer that represents the number of items are actually present in the array so far. Your GroceryList class should have the following constructor: public Grocer yList o Constructs a new empty grocery list. A Grocery List object should have the following methods: public void add (Grocery temorder item) o Adds the given item to this list if the list has fewer than 10 items. public double get TotalCost o Returns the total sum cost of all grocery item orders in this list. The GroceryItemorder class should store information about a purchase item, including its name, quantity, and unit price. A Grocery er object should have the following constructor and methods Itemord public Grocery Itemorder (string name, int quantity, double price Perunit) o Constructs an item to purchase with the given name, in the given quantity and the give unit price. public double getcost o Returns the cost of this item in its given quantity. For example, four boxes of cookies that cost $2.30 per unit have a total cost of $9.20. public void se Quantity (int quantity) o sets this grocery item's quantity to be the given value. public string tostring o Returns string representation of this GroceryItemorder object

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 System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions