Explanation of Solution
Define an abstract data type that represents list of names using Java class syntax.
Abstract data type is used to store the data in a structure and provides different method to manipulate the data stored.
//The interface is created using the following method
interface Names
{
// Declare a method pushback()
public void pushback(String str);
// Declare a method popback()
public String popback();
// Declare a method getname()
public String getname (int x);
}
// Interface is implemented by defining the class namelist
class namelist implements Names
{
// Declare an array
private String[] name;
// Declare an integer size
private int size;
// Definition of constructor
public namelist()
{
// Size is initialized
size=0
}
// Define a method pushback()
public void pushback(String str)
{
// Assign string
name[size]=str;
// Increment the size
size++;
}
// Define a method popback()
public String popback()
{
// Decrement the size and return the name
return name[--size];
}
// Define a method getname()
public String getname(int x)
{
// Check the condition
if(x<size)
// Return name
return name[x];
// Otherwise
else
// Return null
return null;
}
// Define a method display()
public void display()
{
// For loop to iterate the loop
for(int i=0;i<size;i++)
{
// Print the names
System...
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
- What is the definition of data structure? What exactly is the abstract data type? Explain your response with an example.arrow_forwardWhat exactly is a data structure? What is the definition of abstract data type? Explain your solution with the help of an example.arrow_forwardWhat exactly is meant by the term "data structure"? What exactly is meant when one refers to something as having the status of an abstract data type? Would you be able to expound on your response by providing an example?arrow_forward
- Computer Science Data Structures Class: (IN JAVA) Make these matrixes in the same program (A = 3x3, D = 3x3, C = 3x5) These all have to have a sequence and MUST be incorporated in the code (such as C is +2 +2 -2) D = 0,1,2,1,2,3,2,3,4 A = 1,2,3,4,5,6,7,8,9 C = %3D 1,3,5,3,5,7,5,7,9,7,9,11,9,11,13arrow_forwardWhat makes up the interface of an Abstract Data Type? Write your answer here.arrow_forwardWhat makes up the interface of an Abstract Data Type? What makes up the implementation of an ADT?arrow_forward
- 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