Ask 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 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.

+5
Answers (1)
  1. 1 December, 14:45
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers