Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE WRITE IN JAVA Please write code for sections that include // Left as an exercise MyList.java import java.util.*; public interface MyList extends Collection {

PLEASE WRITE IN JAVA

Please write code for sections that include // Left as an exercise

MyList.java import java.util.*;

public interface MyList extends Collection { /** Add a new element at the specified index in this list */ public void add(int index, E e);

/** Return the element from this list at the specified index */ public E get(int index);

/** Return the index of the first matching element in this list. * Return -1 if no match. */ public int indexOf(Object e);

/** Return the index of the last matching element in this list * Return -1 if no match. */ public int lastIndexOf(E e);

/** Remove the element at the specified position in this list * Shift any subsequent elements to the left. * Return the element that was removed from the list. */ public E remove(int index);

/** Replace the element at the specified position in this list * with the specified element and returns the new set. */ public E set(int index, E e); @Override /** Add a new element at the end of this list */ public default boolean add(E e) { add(size(), e); return true; }

@Override /** Return true if this list contains no elements */ public default boolean isEmpty() { return size() == 0; }

@Override /** Remove the first occurrence of the element e * from this list. Shift any subsequent elements to the left. * Return true if the element is removed. */ public default boolean remove(Object e) { if (indexOf(e) >= 0) { remove(indexOf(e)); return true; } else return false; } @Override /** Adds the elements in otherList to this list. * Returns true if this list changed as a result of the call */ public default boolean addAll(Collection c) { // Left as an exercise return true; } @Override /** Return true if this list contains the element */ public default boolean contains(Object o) { if(indexOf((E)o)==-1) return false; return true; }

@Override /** Returns true if this collection contains all of the elements in the specified collection. */ public default boolean containsAll(Collection c) { // Left as an exercise return true; }

@Override /** Removes all the elements in otherList from this list * Returns true if this list changed as a result of the call */ public default boolean removeAll(Collection c) { // Left as an exercise return true; }

@Override /** Retains the elements in this list that are also in otherList * Returns true if this list changed as a result of the call */ public default boolean retainAll(Collection c) { // Left as an exercise return true; }

@Override /** Returns an array containing all of the elements in this collection. */ public default Object[] toArray() { Object[] temp = new Object[this.size()]; for (int i = 0; i < this.size(); i++) temp[i]=(Object)(this.get(i)); if (size() > 0) return (E[])temp; else return null; }

@Override /** Returns an array containing all of the elements in this collection; * the runtime type of the returned array is that of the specified array. */ public default T[] toArray(T[] array) { // Left as an exercise return null } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions

Question

State how the Pareto phenomenon pertains to maintenance decisions

Answered: 1 week ago

Question

Describe the seven standard parts of a letter.

Answered: 1 week ago

Question

Explain how to develop effective Internet-based messages.

Answered: 1 week ago

Question

Identify the advantages and disadvantages of written messages.

Answered: 1 week ago