
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
Question
Complete ArrayStack.java, an array-based implementation o the Stack.java interface.
Modify only the bodies of the following methods in the ArrayStack class:
- push
- pop
- top
- isEmpty
- isFull
Nothing else should be modified in ArrayStack.
Write the class ArrayStackTest to test your implementation. Print only the names of the tests and error messages. Give the test method meaningful names (e.g., emptyStackTest).
- Test push, pop, top, and isEmpty immediately after the stack has been instantiated.
- Push an element on an empty stack. Test pop, top, and isEmpty.
- Instantiate a stack with initialCapacity of 1. Push two elements. Check capacity.
- Other tests you deem necessary.
![ArrayStack.java
import java.util. EmptyStackException;
public class ArrayStack<E> implements Stack<E> {
private final static int DEFAULT_CAPACITY = 100;
private final static int EMPTY_INDEX = -1;
private Ell stack;
private int top = EMPTY_INDEX; // Index of the top element on the stack
public ArrayStack() {
this (DEFAULT_CAPACITY);
public Arraystack(int initialCapacity) {
}
initialCapacity = initialCapacity < @ ? @ : initialCapacity;
stack (E[]) new Object[initialCapacityl;
@Override
public void push(E element) {
// TBD as part of an assignment
@Override
public E pop() {](https://content.bartleby.com/qna-images/question/55cddd6a-12fb-4e1b-bd64-bee5ba717ee4/31ec6b3c-c636-44fd-879d-06b2fc15b327/bcc78wu_thumbnail.png)
Transcribed Image Text:ArrayStack.java
import java.util. EmptyStackException;
public class ArrayStack<E> implements Stack<E> {
private final static int DEFAULT_CAPACITY = 100;
private final static int EMPTY_INDEX = -1;
private Ell stack;
private int top = EMPTY_INDEX; // Index of the top element on the stack
public ArrayStack() {
this (DEFAULT_CAPACITY);
public Arraystack(int initialCapacity) {
}
initialCapacity = initialCapacity < @ ? @ : initialCapacity;
stack (E[]) new Object[initialCapacityl;
@Override
public void push(E element) {
// TBD as part of an assignment
@Override
public E pop() {
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 3 steps with 1 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
- Write a Java program to implement the following: Ask the user to enter the names of 3 Books and store them in an ArrayList called Book Remove the second book from the list Add the user to enter a new book name and store to be the first book of the list Ask the user to enter a book name, search for it in list, and print “exist” or “not exist” Print the book name at index 2 Print all list items using loop Print the size of the listarrow_forward4. Say we wanted to get an iterator for an ArrayList and use it to loop over all items and print them to the console. What would the code look like for this? 5. Write a method signature for a method called foo that takes an array as an argument. The return type is void. 6. What is the difference between remove and clear in ArrayLists.arrow_forwardWrite the Java method averageOfDoubles that is passed an array of double values, and returns the average of the array values.You can assume the array length is a positive integer.arrow_forward
- import java.util.Arrays; import java.util.Random; public class Board { /** * Construct a puzzle board by beginning with a solved board and then * making a number of random moves. That some of the possible moves * don't actually change what the board looks like. * * @param moves the number of moves to make when generating the board. */ public Board(int moves) { throw new RuntimeException("Not implemented"); } The board is 5 X 5. You can add classes and imports like rand.arrow_forward4. Now examine the ArrayList methods in the above table, a) Which method retrieves elements from the ArrayList? b) Which method replaces the value of an element that already exists in the ArrayList? c) Which two methods initializes the value of an element? d) How do the two methods in (c) differ? Which method(s) would be appropriate in the above Java program (after we convert it to work with ArrayLists)?arrow_forwardWrite all the code within the main method in the TestTruck class below. Implement the following functionality. Construct two Truck objects: one with any make and model you choose and the second object with gas tank capacity 10. If an exception occurs, print the stack trace. Print both Truck objects that were constructed. import java.lang.IllegalArgumentException ; public class TestTruck { public static void main( String[] args ) { // write your code herearrow_forward
arrow_back_ios
arrow_forward_ios
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