ow to answer the following question in java screen shot shows the ABList class Suppose a list names contains 8 elements. A call to names.set(8, "Albert") results in: A. an exception being thrown. B. an 8 element list with "Albert" as the last element. C. a 9 element list with "Albert" as the last element. D. a 9 element list with "Albert" as the next to last element.   The only index-related method of the ABList class that can make good use of the protected find method is: A. add B. set C. get D. indexOf E. remove   An application can indicate that it wants to use the "natural order" to order the elements of a SortedABList list by: A. passing the constructor an appropriate compareTo method. B. using the parameter-less constructor. C. using the standard list iteration approach. D. always adding elements to the front of the list.   Suppose a list names contains 8 elements. A call to names.add(9, "Albert") results in: A. an exception being thrown. B. an 8 element list with "Albert" as the last element. C. a 9 element list with "Albert" as the last element. D. a 9 element list with null as the next to last element.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

how to answer the following question in java screen shot shows the ABList class

Suppose a list names contains 8 elements. A call to names.set(8, "Albert") results in:

A. an exception being thrown.
B. an 8 element list with "Albert" as the last element.
C. a 9 element list with "Albert" as the last element.
D. a 9 element list with "Albert" as the next to last element.
 

The only index-related method of the ABList class that can make good use of the protected find method is:

A. add
B. set
C. get
D. indexOf
E. remove
 

An application can indicate that it wants to use the "natural order" to order the elements of a SortedABList list by:

A. passing the constructor an appropriate compareTo method.
B. using the parameter-less constructor.
C. using the standard list iteration approach.
D. always adding elements to the front of the list.
 

Suppose a list names contains 8 elements. A call to names.add(9, "Albert") results in:

A. an exception being thrown.
B. an 8 element list with "Albert" as the last element.
C. a 9 element list with "Albert" as the last element.
D. a 9 element list with null as the next to last element.
 
 
//page 1
import jayautillterator:
//page 2
{
if (nymElements ==:
enlarge();
elements[nymElements] = element;
QUMElementst+;
elementsJength)
public class ABList<T> implements Listotertace<T>
{
protected final int DEFCAP = 100; // default capacity
protected int origCarin
protected T] elements;
protected int numElements = 0;// number of elements in this list
// original capacity
// array to hold this listas elements
return true;
}
public boolean remove (T target)
// Removes an element e from this list such that eeguals(target)
// and returns true; if no such element exists, returns false.
{
find(target);
if (found)
{
for (inti= location; į <= numElements - 2; it+)
elements [i] = elements[i+1];
elementsloumElements. - 1] = null;
DuDElements--
}
return found;
}
// set by find method
protected boglean feundi ll true if target found, otherwise false
protected int location; // indicates location of target if found
public ABLISTO
{
elements = (TI) new Object[DEFCAP];
origcar = DEFCAP;
}
public ABListlint orisCan)
{
elements = (TII) new Object[origCanl;
this origCar = origCap:
}
public int sizell
// Returns the number of elements on this list.
{
return numElements:
}
protected void enlərge()
// Increments the capacity of the list by an amount
// equal to the original capacity.
{
// Create the larger array.
TI larger = (T1) new Object[elements,length,+ origCapl;
// Copy the contents from the smaller array into the larger array.
for (int i= 0; i< oumElements; i++)
{
larger[i] = elements[i];
}
public boglean contains (T target)
// Returns true if this list contains an element e such that
// eegyals(target); otherwise, returns false.
{
find(target);
return found;
}
public T get(T target)
// Returns an element e from this list such that e,eguals(target);
// if no such element exists, returns null.
{
find(target);
if (found)
return elements[location];
else
// Reassign elements reference.
elements = larger;
}
protected void find(T target)
// Searches list for an occurence of an element e such that
// e eguals(target). If successful, sets instance variables
// found to true and location to the array index of e. If
// not successful, sets found to false.
{
location = 0;
found = false;
return null;
}
public boglean, isEmptul)
// Returns true if this list is empty; otherwise, returns false.
{
return (nymElements == 0);
}
while (location < DymĒlements)
{
if (elements[location]eguals(target))
{
found = true;
public boglean, isFUllO
// Returns false - the list is unbounded.
{
return false;
}
return;
}
else
location++;
}
}
public void ąddlint,index, T element)
// Throws IndexOutofBoundsException if passed an index argument
// such that index <0 or index > şize().
// Otherwise, adds element to this list at position index; all current
// elements at that index or higher have 1 added to their index.
public boglean addhT element)
// Adds element to end of this list.
Transcribed Image Text://page 1 import jayautillterator: //page 2 { if (nymElements ==: enlarge(); elements[nymElements] = element; QUMElementst+; elementsJength) public class ABList<T> implements Listotertace<T> { protected final int DEFCAP = 100; // default capacity protected int origCarin protected T] elements; protected int numElements = 0;// number of elements in this list // original capacity // array to hold this listas elements return true; } public boolean remove (T target) // Removes an element e from this list such that eeguals(target) // and returns true; if no such element exists, returns false. { find(target); if (found) { for (inti= location; į <= numElements - 2; it+) elements [i] = elements[i+1]; elementsloumElements. - 1] = null; DuDElements-- } return found; } // set by find method protected boglean feundi ll true if target found, otherwise false protected int location; // indicates location of target if found public ABLISTO { elements = (TI) new Object[DEFCAP]; origcar = DEFCAP; } public ABListlint orisCan) { elements = (TII) new Object[origCanl; this origCar = origCap: } public int sizell // Returns the number of elements on this list. { return numElements: } protected void enlərge() // Increments the capacity of the list by an amount // equal to the original capacity. { // Create the larger array. TI larger = (T1) new Object[elements,length,+ origCapl; // Copy the contents from the smaller array into the larger array. for (int i= 0; i< oumElements; i++) { larger[i] = elements[i]; } public boglean contains (T target) // Returns true if this list contains an element e such that // eegyals(target); otherwise, returns false. { find(target); return found; } public T get(T target) // Returns an element e from this list such that e,eguals(target); // if no such element exists, returns null. { find(target); if (found) return elements[location]; else // Reassign elements reference. elements = larger; } protected void find(T target) // Searches list for an occurence of an element e such that // e eguals(target). If successful, sets instance variables // found to true and location to the array index of e. If // not successful, sets found to false. { location = 0; found = false; return null; } public boglean, isEmptul) // Returns true if this list is empty; otherwise, returns false. { return (nymElements == 0); } while (location < DymĒlements) { if (elements[location]eguals(target)) { found = true; public boglean, isFUllO // Returns false - the list is unbounded. { return false; } return; } else location++; } } public void ąddlint,index, T element) // Throws IndexOutofBoundsException if passed an index argument // such that index <0 or index > şize(). // Otherwise, adds element to this list at position index; all current // elements at that index or higher have 1 added to their index. public boglean addhT element) // Adds element to end of this list.
//page 3
{
if (index < 0) || (index > şizel))
throw new IndexQutofBeundsException("lllegal index of " + index +
//page 4
Thold = elements[index];
for (int i = index; į< numElements-1; i++)
elements [i] = elementsli + 1);
elements[numElements-1] = null;
DumElements-
return hold;
}
"passed to ABIList add method.\n");
if (nymElements. ==elenents.length)
eplarge();
for (int i= DymElements: i > index; i-)
elements[i] = elementsli - 1);
public Iterator<T> iterator)
// Returns an Iterator over this list.
{
return new Iterator<T>()
{
private int previeuskes = -1;
elements[index] = element;
ounFlementst+;
}
public T setlint index, T newElement)
// Throws IndexQutofBaundsExcertion if passed an index argument
// such that index <0 or index >= şize().
// Otherwise, replaces element on this list at position index with
// newElement and returns the replaced element.
{
if ((index < 0) || (index>= sizel))
throw new IndexOutOfBoundsException("Illegal index of " + index +
public boglean basNext)
// Returns true if the iteration has more elements; otherwise returns false.
{
return (previousPos < (sizel) - 1));
}
public T pext()
// Returns the next element in the iteration.
// Throws NoSuchElementException - if the iteration has no more elements
{
if (basNext()
throw new IndexQutOfBoundsException("Illegal invocation of next " +
passed to ABLIST set method.\n");
Thold = elements[index];
elements[index] = pewElementi
return hold;
}
"in ABIist iterator.\n");
BrevieusPest+;
return elements[previousPes);
}
public T getlint,index)
// Throws IndexQutofBaundsExcertion if passed an index argument
// such that index <0 or index >= şize().
// Otherwise, returns the element on this list at position index.
{
if ((index < 0) || (index>= size()
throw new IndexQutQfBQundsException("Illegal index of " + index +
public void removel)
// Removes from the underlying representation the last element returned
// by this iterator. This method should be called only once per call to
// next(). The behavior of an iterator is unspecified if the underlying
// representation is modified while the iteration is in progress in any
// way other than by calling this method.
{
for (int i = previousPos; i<= DumElements - 2; i++)
elements[i] = elements[i+1];
elementslnumElements. - 1] = null;
DumElements-;
previeusPes-;
}
};
}
}
passed to ABLIST get method. \n");
return elements[index];
}
public int indexQACT target)
// If this list contains an element e such that e.eguals(target),
// then returns the index of the first such element.
// Otherwise, returns -1.
{
find(target);
if (found)
return location;
else
return -1;
}
public T removelint index)
// Throws IndexQutorBaundsExsertion if passed an index argument
// such that index <0 or index >= şize().
// Otherwise, removes element on this list at position index and
// returns the removed element; all current elements at positions
// higher than that index have 1 subtracted from their position.
{
if ((index < 0) || (index>= şize(Q))
throw new IndexOutOfBoundsException("Illegal index of " + index +
passed to ABlist remove method.\n");
Transcribed Image Text://page 3 { if (index < 0) || (index > şizel)) throw new IndexQutofBeundsException("lllegal index of " + index + //page 4 Thold = elements[index]; for (int i = index; į< numElements-1; i++) elements [i] = elementsli + 1); elements[numElements-1] = null; DumElements- return hold; } "passed to ABIList add method.\n"); if (nymElements. ==elenents.length) eplarge(); for (int i= DymElements: i > index; i-) elements[i] = elementsli - 1); public Iterator<T> iterator) // Returns an Iterator over this list. { return new Iterator<T>() { private int previeuskes = -1; elements[index] = element; ounFlementst+; } public T setlint index, T newElement) // Throws IndexQutofBaundsExcertion if passed an index argument // such that index <0 or index >= şize(). // Otherwise, replaces element on this list at position index with // newElement and returns the replaced element. { if ((index < 0) || (index>= sizel)) throw new IndexOutOfBoundsException("Illegal index of " + index + public boglean basNext) // Returns true if the iteration has more elements; otherwise returns false. { return (previousPos < (sizel) - 1)); } public T pext() // Returns the next element in the iteration. // Throws NoSuchElementException - if the iteration has no more elements { if (basNext() throw new IndexQutOfBoundsException("Illegal invocation of next " + passed to ABLIST set method.\n"); Thold = elements[index]; elements[index] = pewElementi return hold; } "in ABIist iterator.\n"); BrevieusPest+; return elements[previousPes); } public T getlint,index) // Throws IndexQutofBaundsExcertion if passed an index argument // such that index <0 or index >= şize(). // Otherwise, returns the element on this list at position index. { if ((index < 0) || (index>= size() throw new IndexQutQfBQundsException("Illegal index of " + index + public void removel) // Removes from the underlying representation the last element returned // by this iterator. This method should be called only once per call to // next(). The behavior of an iterator is unspecified if the underlying // representation is modified while the iteration is in progress in any // way other than by calling this method. { for (int i = previousPos; i<= DumElements - 2; i++) elements[i] = elements[i+1]; elementslnumElements. - 1] = null; DumElements-; previeusPes-; } }; } } passed to ABLIST get method. \n"); return elements[index]; } public int indexQACT target) // If this list contains an element e such that e.eguals(target), // then returns the index of the first such element. // Otherwise, returns -1. { find(target); if (found) return location; else return -1; } public T removelint index) // Throws IndexQutorBaundsExsertion if passed an index argument // such that index <0 or index >= şize(). // Otherwise, removes element on this list at position index and // returns the removed element; all current elements at positions // higher than that index have 1 subtracted from their position. { if ((index < 0) || (index>= şize(Q)) throw new IndexOutOfBoundsException("Illegal index of " + index + passed to ABlist remove method.\n");
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education