Discuss the BagInterface interface. Does this bag interface imply anything about
ID: 3783647 • Letter: D
Question
Discuss the BagInterface interface.
Does this bag interface imply anything about the order of the items in a bag?
Are they ordered or unordered?
Does this bag interface imply anything about the number of occurrences of an item in a bag?
Can an item with the same value appear more than once?
Which of its methods should appear in the interface of any collection?
Discuss why interfaces are separated from and come before implementations.
please answer this question by typing it. If possible I need the questions answered within a hour or so we are working in python not java
Explanation / Answer
Code:
class bagInterface:
def __init__(self,items):
itemlist = set()
itemlist = items
def getNumberofitems(self):
return len(itemlist)
def getItemList(self)
return itemlist
def addItem(self,item):
itemlist.add(item)
def deleteItem(self,item):
itemlist.remove(item)
We are using set to represents item. Hence items in the bag are unordered. We can get number of an item in a bag.
Item with same value does not appear more than once as we are using set.
All the methods that we are using is given in the code.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.