Ask Question
21 February, 13:51

Write a class named grocerylist that represents a list of items to buy from the market. write another class called item that represents a request to purchase a particular item in a given quantity (for example four boxes of cookies). the grocerylist class should use an array field to store items and to keep track of its size (number of the items in the list so far). assume that a grocery list will have no more than 50 items.

+4
Answers (1)
  1. 21 February, 16:32
    0
    Class Item {

    / / item class attributes

    string itemName;

    int itemQuantity;

    double itemPrice;

    ...

    }

    class grocerylist {

    / / you can use arrays or any other containers like ArrayList, Vectors, ... etc depends on programming language you use

    Item[50] itemList;

    int size;

    public grocerylist () {

    this. size = 0;

    }

    public void addItem (Item i) {

    itemList[size] = i;

    size = size + 1; / / Or size++

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a class named grocerylist that represents a list of items to buy from the market. write another class called item that represents a ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers