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 is an Abstract Data Type (ADT) and how does it work?ADTs provide a number of benefits, which we will list below.What are some of the ways in which the idea of heredity aids in problem solving?arrow_forwardCompilers for contemporary programming languages may implement abstract data types in a number of ways. Exists a universally applicable definition, and if not, why not? Can you share an example?arrow_forward
- Compatibility between Abstract Data Types and Object-Oriented Programming? New concepts include object-oriented programming and abstract data types. With intent. Occasionally must you disagree?arrow_forwardWhat exactly is an Abstract Data Type (ADT)? What are a few of the advantages of ADTs? In what ways does the concept of heredity facilitate problem solving?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