
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Complete an Array-Based implementation of the ADT List including the following main class:
![// *********
// Interface ListInterface for the ADT list.
// ***************************
public interface ListInterface {
public boolean isEmpty();
public int size();
public void add (int index, Object item)
}
***
throws ListIndexOutOfBoundsException,
public Object get (int index)
public void remove(int index)
// ********
ListException;
public void removeAll();
// end ListInterface
throws ListIndexOutOfBounds Exception;
throws ListIndexOutOfBoundsException;
The following class implements the interface List Interface, using arrays.
// Array-based implementation of the ADT list.
// *****************************
} // end size
public class ListArrayBased implements List Interface {
private static final int MAX_LIST = 50;
private Object items []; // an array of list items
private int numItems; // number of items in list
public ListArrayBased () {
items = new Object [MAX_LIST];
numItems = 0;
} // end default constructor
public boolean isEmpty() {
return (numItems == 0);
} // end isEmpty
public int size() {
return numItems;
public void removeAll() {
// Creates a new array; marks old array for
// garbage collection.
items = new Object [MAX_LIST];
numItems = 0;
} // end removeAll
public void add(int index, Object item)
throws ListIndexOutOfBounds Exception {
if (numItems > MAX_LIST) {
throw new ListException ("ListException on add");
} // end if](https://content.bartleby.com/qna-images/question/5ccb13ef-bf62-4bab-95f5-f0fc9e7adadc/000dd6c6-23ee-4999-b05f-01b965f52498/lgvpi9q_thumbnail.png)
Transcribed Image Text:// *********
// Interface ListInterface for the ADT list.
// ***************************
public interface ListInterface {
public boolean isEmpty();
public int size();
public void add (int index, Object item)
}
***
throws ListIndexOutOfBoundsException,
public Object get (int index)
public void remove(int index)
// ********
ListException;
public void removeAll();
// end ListInterface
throws ListIndexOutOfBounds Exception;
throws ListIndexOutOfBoundsException;
The following class implements the interface List Interface, using arrays.
// Array-based implementation of the ADT list.
// *****************************
} // end size
public class ListArrayBased implements List Interface {
private static final int MAX_LIST = 50;
private Object items []; // an array of list items
private int numItems; // number of items in list
public ListArrayBased () {
items = new Object [MAX_LIST];
numItems = 0;
} // end default constructor
public boolean isEmpty() {
return (numItems == 0);
} // end isEmpty
public int size() {
return numItems;
public void removeAll() {
// Creates a new array; marks old array for
// garbage collection.
items = new Object [MAX_LIST];
numItems = 0;
} // end removeAll
public void add(int index, Object item)
throws ListIndexOutOfBounds Exception {
if (numItems > MAX_LIST) {
throw new ListException ("ListException on add");
} // end if
![if (index >= 0 && index <= numItems) {
// make room for new element by shifting all items at
// positions >= index toward the end of the
// list (no shift if index == numItems+1)
for (int pos = numItems; pos >= index; pos--) {
items [pos+1] = items [pos];
}
} // end for
// insert new item
items [index] = item;
numItems++;
}
else { // index out of range
throw new ListIndexOutOfBoundsException (
"ListIndexOutOfBounds Exception on add");
// end if
}
} //end add
public Object get (int index)
if (index >= 0 && index < numItems) {
return items [index];
}
else { // index out of range
throw new ListIndexOutOfBoundsException (
"ListIndexOutOfBoundsException on get");
} // end if
} // end get
throws ListIndexOutOfBounds Exception {
public void remove(int index)
if (index >= 0 && index < numItems) {
// delete item by shifting all items at
// positions> index toward the beginning of the list
// (no shift if index == size)
numItems--;
for (int pos= index+1; pos <= size(); pos++) {
items [pos-1] = items [pos];
// end for
} // end if
} // end remove
throws ListIndexOutOfBounds Exception {
}
else { // index out of range
throw new ListIndexOutOfBoundsException(
"ListIndexOutOfBounds Exception on remove");
// end ListArrayBased
The following program segment demonstrates the use of ListArrayBased:
static public void main(String args[]) {
ListArrayBased aList = new ListArrayBased ();
String dataItem;
aList.add(0, "Cathryn");
dataItem = (String) aList.get(0);](https://content.bartleby.com/qna-images/question/5ccb13ef-bf62-4bab-95f5-f0fc9e7adadc/000dd6c6-23ee-4999-b05f-01b965f52498/rmsp3on_thumbnail.png)
Transcribed Image Text:if (index >= 0 && index <= numItems) {
// make room for new element by shifting all items at
// positions >= index toward the end of the
// list (no shift if index == numItems+1)
for (int pos = numItems; pos >= index; pos--) {
items [pos+1] = items [pos];
}
} // end for
// insert new item
items [index] = item;
numItems++;
}
else { // index out of range
throw new ListIndexOutOfBoundsException (
"ListIndexOutOfBounds Exception on add");
// end if
}
} //end add
public Object get (int index)
if (index >= 0 && index < numItems) {
return items [index];
}
else { // index out of range
throw new ListIndexOutOfBoundsException (
"ListIndexOutOfBoundsException on get");
} // end if
} // end get
throws ListIndexOutOfBounds Exception {
public void remove(int index)
if (index >= 0 && index < numItems) {
// delete item by shifting all items at
// positions> index toward the beginning of the list
// (no shift if index == size)
numItems--;
for (int pos= index+1; pos <= size(); pos++) {
items [pos-1] = items [pos];
// end for
} // end if
} // end remove
throws ListIndexOutOfBounds Exception {
}
else { // index out of range
throw new ListIndexOutOfBoundsException(
"ListIndexOutOfBounds Exception on remove");
// end ListArrayBased
The following program segment demonstrates the use of ListArrayBased:
static public void main(String args[]) {
ListArrayBased aList = new ListArrayBased ();
String dataItem;
aList.add(0, "Cathryn");
dataItem = (String) aList.get(0);
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images

Knowledge Booster
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
- in C++ Define a new “Word” class that must inherit from the given Name class. This class manages a dictionary word info: name (string) and its definition (string). It must prevent the creation of a Word object with either an empty or all-blank word or definition. This class must at least complete the methods defined in the Name class: toString method returns a string representation of the Word object in the format of “WORD( <word> ) DEFINITION( <definition> ) such as WORD(school) DEFINITION(an educational institution) contains method that accepts a search string and returns true if either word or definition contains the search string as a substring. It returns false otherwise. isTheSame method that compares two Word objects and returns true only if both Word objects have the exact same word and definition and false otherwise. Please note that if the given object in the parameter is not a Word object, it will return false.arrow_forwardRe-write Sample Program 11.2 so that it works for an array of structures. Write the program so that it compares 6 circles. You will need to come up with a new way of determining which circle’s center is closest to the origin. Sample code 11.2 #include <iostream>#include <cmath> // necessary for pow function#include <iomanip>using namespace std;struct circle // declares the structure circle{ // This structure has 6 membersfloat centerX; // x coordinate of centerfloat centerY; // y coordinate of centerfloat radius;float area;float circumference;float distance_from_origin;};const float PI = 3.14159;int main(){circle circ1, circ2; // defines 2 circle structure variablescout << "Please enter the radius of the first circle: ";cin >> circ1.radius;cout << endl<< "Please enter the x-coordinate of the center: ";cin >> circ1.centerX;cout << endl<< "Please enter the y-coordinate of the center: ";cin >>…arrow_forward
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education