COP3530 – Assignment 1 solution


Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment


5/5 - (3 votes)

Consider the Bag interface given below. Write and test an ArrayBag class the implements the

public interface Bag
public boolean isEmpty(); // returns true if bag is empty, false otherwise
public void print(); // prints the content of the bag
public void add(String s); // adds string s to the bag
public void remove(String s); // remove all occurrences of string s
public int count(String s); // returns number of occurrences of string s in the bag


The assignment is to be completed individually. Questions are based on Week 1 and 2 content.

You are allowed to use all of the code given in the lectures (for example, the implementation of the
methods of the ArrayList class). In those cases, make sure you properly credit its source.


Students are expected to structure the code as indicated in the UML class diagram:

+static void main(String[] args)

+boolean isEmpty()
+void print()
+void add(String s)
+void remove(String s)
+int count(String s)

-int SIZE
-int[] bag
-int length
+boolean isEmpty()
+void print()
+void add(String s)
+void remove(String s)
+int count(String s)