I need the program to run well in java , I want a photo to check that it works and the code , I have seen many in answers
Posted: Fri Jul 01, 2022 5:46 am
I need the program to run well in java , I want aphoto to check that it works and the code , I have seen many inchegg but all of them have errors and they do not work for me Iwould like you to explain how you did it
(Implement set operations in MyList) The implementations of themethods addAll, removeAll, retainAll, toArray(), and toArray(T[])are omitted in the MyList interface. Implement these methods. Testyour new MyList class using the code atliveexample.pearsoncmg.com/test/Exercise24_01Test.txt.
PreviousNext
import java.util.Collection;public interface jennifernava4<E> extends Collection<E>{/*** 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 thislist.** 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;}}@Overridepublic default boolean containsAll(Collection<?> c) {//looping through each item in cfor (Object e : c) {//if this list does not contain element e, returning falseif (!this.contains(e)) {return false;}}//all elements on c is present in this listreturn true;}/*** Adds the elements in otherList to this list.** Returns true if this list changed as a result of the call*/@Overridepublic default boolean addAll(Collection<? extends E>otherList) {//initially list isnt changedboolean changed = false;
//looping through each element in other listfor (E element : otherList) {//adding element to this list, if addition returns true, thenlist//is changedif (this.add(element)) {changed = true;}}return changed;}@Overridepublic default boolean removeAll(Collection<?> c) {boolean changed = false;for (Object ob : c) {//removing current element in c from this setif (this.remove(ob)) {//removal success, list is modified.changed = true;}}return changed;}/*** Retains the elements in this list that are also inotherList** Returns true if this list changed as a result of the call*/@Overridepublic default boolean retainAll(Collection<?> c) {boolean changed = false;
int index = size() - 1;//looping from last index to firstwhile (index >= 0) {//getting elementObject ob = get(index);//if c contains this element, removing itif (c.contains(ob)) {remove(index);//list changed.changed = true;}//moving to previous indexindex--;}return changed;}@Overridepublic default Object[] toArray() {//creating an Object arrayObject array[] = new Object[size()];//copying elementsfor (int i = 0; i < size(); i++) {array = get(i);}//returning itreturn array;}@Overridepublic default <T> T[] toArray(T[] array) {
//if array is not big enough to hold all elements,reinitializing arrayif (array.length < size()) {array = (T[]) new Object[size()];}//copying all elements to arrayfor (int i = 0; i < size(); i++) {array = (T) get(i);}//returningreturn array;}}
(Implement set operations in MyList) The implementations of themethods addAll, removeAll, retainAll, toArray(), and toArray(T[])are omitted in the MyList interface. Implement these methods. Testyour new MyList class using the code atliveexample.pearsoncmg.com/test/Exercise24_01Test.txt.
PreviousNext
import java.util.Collection;public interface jennifernava4<E> extends Collection<E>{/*** 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 thislist.** 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;}}@Overridepublic default boolean containsAll(Collection<?> c) {//looping through each item in cfor (Object e : c) {//if this list does not contain element e, returning falseif (!this.contains(e)) {return false;}}//all elements on c is present in this listreturn true;}/*** Adds the elements in otherList to this list.** Returns true if this list changed as a result of the call*/@Overridepublic default boolean addAll(Collection<? extends E>otherList) {//initially list isnt changedboolean changed = false;
//looping through each element in other listfor (E element : otherList) {//adding element to this list, if addition returns true, thenlist//is changedif (this.add(element)) {changed = true;}}return changed;}@Overridepublic default boolean removeAll(Collection<?> c) {boolean changed = false;for (Object ob : c) {//removing current element in c from this setif (this.remove(ob)) {//removal success, list is modified.changed = true;}}return changed;}/*** Retains the elements in this list that are also inotherList** Returns true if this list changed as a result of the call*/@Overridepublic default boolean retainAll(Collection<?> c) {boolean changed = false;
int index = size() - 1;//looping from last index to firstwhile (index >= 0) {//getting elementObject ob = get(index);//if c contains this element, removing itif (c.contains(ob)) {remove(index);//list changed.changed = true;}//moving to previous indexindex--;}return changed;}@Overridepublic default Object[] toArray() {//creating an Object arrayObject array[] = new Object[size()];//copying elementsfor (int i = 0; i < size(); i++) {array = get(i);}//returning itreturn array;}@Overridepublic default <T> T[] toArray(T[] array) {
//if array is not big enough to hold all elements,reinitializing arrayif (array.length < size()) {array = (T[]) new Object[size()];}//copying all elements to arrayfor (int i = 0; i < size(); i++) {array = (T) get(i);}//returningreturn array;}}