Question: 3 . Programming Task In this assignment, two types of containers are defined: MyList and MySet. These containers can store an unlimited number of objects

3. Programming Task
In this assignment, two types of containers are defined: MyList and MySet. These containers can store an unlimited number of objects and have several methods defined for them, as shown in the UML below.
The key distinction between MyList and MySet lies in their handling of duplicate objects. MySet does not permit duplicate objects; therefore, if the add () method is called with an object that already exists in the container, it will not be added again. Conversely, MyList does not impose this restriction and allows duplicate objects to be stored.
Also, MyList provides access to its items via their index, enabling retrieval of specific elements. However, this functionality is not available in MySet.
Your task for this lab is to implement the components of the two subclasses according to the javaDoc given in the starter code.
Task 1: Class Container
For this task, please implement isEmpty() and getSize() for the Container class according to the descriptions provided in the given JavaDoc. Task 1: Class Container
For this task, please implement isEmpty() and getsize() for the Container class according to the descriptions provided in the given JavaDoc.
Task 2: Class MyList
For this task, you need to implement all the methods of this class as explained in the javaDoc. Some of the methods inherited form class Container should be overridden.
Task 3: Class MySet
For this task, you need to implement all the methods of this class as explained in the javaDoc. Some of the methods inherited form class Container should be overridden. package Labb;
```
public class Container {
// do not change the value of the following constant.
protected final int ORIGINAL SIZE =10;
protected object[] list; // is a container that stores the element of MyList
protected Object[] set; // is a container that stores the element of MySet
protected int size; // this variable holds the actual number of elements that are stored in either of the containers (i.e. MyList or MySet).
-/**
* This method adds the obi. to the end of the container.
* @param obi is the object that is added to the container.
*/
- void add(Object obj){
// insert your code here. Only one line should be added here.
}
```
-/**
* This method removes the obji, from the container.
* It shifts all the elements to make sure that removal of the element
* does not create a whole in the container.
* @param obi is the object that is removed from the container.
* @return It returns the object that was removed.
*/
- Object remove(Object obj){
// insert your code here, you may want to change the return value
return null;
}
-/**
* This method returns true if the container is empty.
* @return It returns true if the container is empty, otherwise false.
*/
- boolean isEmpty(){
// you may want to change the return value
return true;
}
-/**
* This method returns the number of elements stored in the container.
* @return It returns the number of elements in the container.
*/
- int getSize()\{
// you may what to change the return value
return 0;
}
\(\bullet /+t \)
*
* This class simulates an ArrayList, where you can add unlimited number of
* elements to the list. ```
class MyList extends Container{
/**
* This is the default constructor that sets all the instance variables to their defualt value.
*/
- public MyList (){
//insert your code here
}
-/**
* This method returns the element that is stored at index index .
* @param index is the index at which the element is accessed and returned.
: @return it returns the element stored at the given index .
*/
- public Object get(int index){
// insert your code here, you may want to change the return value
return null;
}
/**
* This method overrrides the add method defined in class container, by
* adding the Obi. to the back of list array.
* The original size of the array , is defined by ORIGINAL_SIzE , however, it is possible that
* more elements is added to this array. In case the array does not have enough capacity to add one more element, it grows itself
* by doubling the size of list array.
*/
- @override
void add(Object obj){
// insert your code here
}
-/**
* This method removes the first occurrence of obi.
* from list
* @pre obi exists in the list array.
*
*/
- @override
Object remove(Object obj){
// insert your code here. You may wnat to change the return value
return null;
}
}
}
```
-/**
* This method returns the elements of the MyList in a form of
*[obj1 obj2 obj3...]
\(+\)
- eoverride
public String toString(```
class MySet extends Container{
public MySet(){
// insert your code here.
}
-/**
* This method overrrides the add method defined in class container, by
* adding the obji, to the back of set array.
x The original size of the set , is defined by ORIGINAL SIME , however, it is possible that
* more elements is added to this set. In case the set does not have enough capacity to add one more element, it grows itself
3 . Programming Task In this assignment, two

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!