Answered Essay: Implement the interface listed below to create a stack class written in Java using an array. In addition, create a driver class th

Java:

Help me with the following Array Based Stack lab please:

Implement the interface listed below to create a stack class written in Java using an array. In addition, create a driver class that tests your stack class. The specification and implementation of our stack is different from the books implementation, but they are very similar. Recall that a stack is a linear collection where insertion and deletion occur at one end only. A stack is a last in, first out (LIFO) data structure. The last element to be put on the stack will be the first element that gets removed. Stacks can be applied to numerous programming problems such as the evaluation of arithmetic expressions An abstract data type (ADT) defines the operations that can be performed on the collection (data structure). Whenever you create a data structure, you should formally list and describe the operations that can be performed on it. That way, you can separate the interface to the collection from the implementation technique used to create it. Operation Description push pop peek Adds an element to the top of the stack. Removes an element from the top of the stack. Examines the element at the top of the stack. Returns true if the stack is em Returns true if the stack is full. Returns the number of elements in the stack. isEmpty isFull s1Ze public interface StackIntADT public void push(int element); public int pop0; public int peek0: public boolean isEmpty0; public boolean isFullO; public int size0;

Implement the interface listed below to create a stack class written in Java using an array. In addition, create a driver class that tests your stack class. The specification and implementation of our stack is different from the books implementation, but they are very similar. Recall that a stack is a linear collection where insertion and deletion occur at one end only. A stack is a last in, first out (LIFO) data structure. The last element to be put on the stack will be the first element that gets removed. Stacks can be applied to numerous programming problems such as the evaluation of arithmetic expressions An abstract data type (ADT) defines the operations that can be performed on the collection (data structure). Whenever you create a data structure, you should formally list and describe the operations that can be performed on it. That way, you can separate the interface to the collection from the implementation technique used to create it. Operation Description push pop peek Adds an element to the top of the stack. Removes an element from the top of the stack. Examines the element at the top of the stack. Returns true if the stack is em Returns true if the stack is full. Returns the number of elements in the stack. isEmpty isFull s1Ze public interface StackIntADT public void push(int element); public int pop0; public int peek0: public boolean isEmpty0; public boolean isFullO; public int size0;

Expert Answer

 

**StackIntAdt.java

public interface StackIntAdt

{

public void push(int element);

public int pop();

public int peek();

public boolean isEmpty();

public boolean isFull();

public int size();

}

**IntStack.java

public class IntStack implements StackIntAdt {

private int stackPointer;

private int size;

private int array[];

public IntStack() {

this.stackPointer = -1;

this.size = 10;

array = new int[size];

System.out.println(“Initialized the stack with default size of 10”);

// TODO Auto-generated constructor stub

}

public IntStack(int i) {

// TODO Auto-generated constructor stub

this.stackPointer = -1;

this.size = i;

array = new int[size];

System.out.println(“Initialized the stack with size of ” + this.size);

}

@Override

public void push(int element) {

// TODO Auto-generated method stub

if(!this.isFull()){

this.stackPointer++;

this.array[this.stackPointer] = element;

System.out.println(“Pushed the element ” + element + ” into the stack”);

}

else

System.out.println(“The stack is full”);

}

@Override

public int pop() {

// TODO Auto-generated method stub

if(!this.isEmpty()){

int poppedElement = this.array[this.stackPointer];

this.stackPointer–;

return poppedElement;

}

else{

return -1;

}

}

@Override

public int peek() {

// TODO Auto-generated method stub

return this.array[this.stackPointer];

}

@Override

public boolean isEmpty() {

// TODO Auto-generated method stub

if(this.stackPointer == 0)

return true;

else

return false;

}

@Override

public boolean isFull() {

// TODO Auto-generated method stub

if(this.stackPointer == this.size – 1)

return true;

else

return false;

}

@Override

public int size() {

// TODO Auto-generated method stub

return this.size;

}

}

**Driver.java

public class Driver {

public static void main(String args[]){

IntStack object1 = new IntStack();

boolean isEmpty = object1.isEmpty();

if(isEmpty)

System.out.println(“The stack is empty”);

else

System.out.println(“The stack is not empty”);

object1.push(5);

object1.push(1);

object1.push(9);

object1.push(55);

object1.push(4);

object1.push(97);

int peekElement = object1.peek();

System.out.println(“The peek element is ” + peekElement);

object1.push(22);

object1.push(23);

boolean isFull = object1.isFull();

if(isFull)

System.out.println(“The stack is full”);

else

System.out.println(“The stack is not full”);

object1.push(29);

object1.push(26);

int pop = object1.pop();

if(pop == -1)

System.out.println(“The stack is empty”);

else

System.out.println(“Popped element is ” + pop);

/*

* Scanner in = new Scanner(System.in);

* int userSize = in.nextInt();

* IntStack object2 = new IntStack(10);

* Now perform the push, pop operations

*/

}

}

**Screenshot of sample input and output:

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.