Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the ListArray.java file to implement the following missing methods. Also add a constructor that creates a list with the argument element as its only

Modify the ListArray.java file to implement the following missing methods. Also add a constructor that creates a list with the argument element as its only content and a copy constructor.

image text in transcribed

the rest of the java files are here: https://pastebin.com/Gx3zXEGa

the code to be modified is below

***LISTARRAYLISTBASED.JAVA to be MODIFIED*****

/** * Array-based implementation of the ADT list. */ import java.util.ArrayList; import java.util.Iterator;

public class ListArrayListBased implements ListInterface, Iterable {

/** array on which the list is based */ private ArrayList items = new ArrayList(); /** default Constructor */ //TO COMPLETE

/** constructor with the first item: constructs a list with the * specified item as single element of this list * @param item first element of the list */ // TO COMPLETE /** copy constructor: create a duplicate of the specified list * @param list to be copied */ //TO COMPLETE

/** Tests if this list has no elements. * @return true if this list has no elements; * false otherwise. */ public boolean isEmpty() { return items.isEmpty(); } // end isEmpty

/** * Returns the number of elements in this list. * @return the number of elements in this list. */ public int size() { return items.size(); } // end size /** * Remove all the elements in this list. */ public void removeAll() { items.clear(); } // end removeAll

/** * Inserts the specified element at the specified position in this * list. Shifts the element currently at that position (if any) * and any subsequent elements to the right (adds one to their * indices). * @param index index at which the specified element is to be * inserted. * @param item element to be inserted. * @throws IndexOutOfBoundsException - if index is out of range * (index size()). */ public void add(int index, E item) throws ListIndexOutOfBoundsException { if (index >= 1 && index

/** * appends the specified element to the end of this list. * @param elt element to be added at the end of the list */ // TO COMPLETE /** * Returns the element at the specified position in this list. * @param index index of element to return. * @return the element at the specified position in this list. * @throws IndexOutOfBoundsException - if index is out of range * (index size()). */ public E get(int index) throws ListIndexOutOfBoundsException { if (index >= 1 && index

/** * Removes the element at the specified position in this * list. Shifts any subsequent elements to the left (subtracts one * from their indices). * @param index the index of the element to remove * @throws IndexOutOfBoundsException - if index is out of range * (index size()). */ public void remove(int index) throws ListIndexOutOfBoundsException { if (index >= 1 && index index toward the beginning of the list // (no shift if index == size) items.remove(index-1); } else { // index out of range throw new ListIndexOutOfBoundsException( "ListIndexOutOfBoundsException on remove"); } // end if } //end remove

/** delete * delete the the specified element in this list if exists. Shifts * any subsequent elements to the left (subtracts one from their * indices). * @param elt the element, if it exists, to delete */ // TO COMPLETE /** contains * Looks for the index of the specified element in this list. If * the element is not present, the method returns -1 * @param elt the element which index is looked for. * @return either the index of the location in the list where the * argument is present or -1 if the argument is not * contained in the list. */ // TO COMPLETE

/** display * Prints all the elements in this list on the console in sequence */ // TO COMPLETE

/** method to make the class iterable */

public Iterator iterator(){ return items.iterator(); }

@Override public void append(E elt) { // TODO Auto-generated method stub }

@Override public void delete(E elt) { // TODO Auto-generated method stub }

@Override public int contains(E elt) { // TODO Auto-generated method stub return 0; }

@Override public void display() { // TODO Auto-generated method stub }

} // end ListVectorBased

Modify the ListArrayListBased.java file to implement the following missing methods in ListArravListBased class: contains returns either the index of the location in the list where the argument is present or -1 if the argument is not contained in the list, append appends the argument to the end of the list, display displays the list items in sequence, and delete checks if a given item is contained in the list, and if it exists, deletes it Also add a constructor that creates a list with the argument element as its only content and a copy constructor

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

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

More Books

Students also viewed these Databases questions

Question

What are the functions of top management?

Answered: 1 week ago

Question

Bring out the limitations of planning.

Answered: 1 week ago

Question

Why should a business be socially responsible?

Answered: 1 week ago

Question

Discuss the general principles of management given by Henri Fayol

Answered: 1 week ago