Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Main topics: Inheritance Program Specification: A Stack is a simple container that is initially empty and need only support three simple operations: isEmpty -

Java

Main topics:

Inheritance

Program Specification:

A Stack is a simple container that is initially empty and need only support three simple operations:

isEmpty - reports true if the stack contains no values, otherwise reports false.

push value - adds value onto the stack.

pop - removes the most currently pushed value on the stack FILO.

You are to extend your DynArray class to implement a stack which can hold Double values and adheres to the following:

Mandatory Instance methods:

public int size()

// returns the number of values which are currently on the stack

public boolean isEmpty()

// returns true only if there are no values on the stack

public void push(Double value)

// add the specified value onto the stack

public Double pop()

// if the stack is not empty,

// remove and returns the most currently pushd value on the stack

// otherwise,

// returns Double.NaN

public void stackDump()

// print all of the values currenty on the stack, in the order that

// they would be popd off of the stack

A Queue is a simple container that is initially empty and need only support three simple operations:

isEmpty - reports true if the queue contains no values, otherwise reports false.

que value - adds value into the queue.

deQue - removes the least currently queed value in the queue FIFO.

You are to extend your DynArray class to implement a queue which can hold Double values and adheres to the following:

Mandatory Instance methods:

public int size()

// returns the number of values which are currently in the queue

public boolean isEmpty()

// returns true only if there are no values in the queue

public void que(Double value)

// add the specified value into the queue

public Double deQue()

// if the queue is not empty,

// remove and returns the least currently qued value in the queue

// otherwise,

// returns Double.NaN

public void queueDump()

// print all of the values currenty in the queue, in the order that

// they would be deQued from the queue

Your Class must also work with the following Driver Class StackQueueDriver:

public class StackQueueDriver

{

public static void main(String[] args)

{

Stack myStack = new Stack();

Queue myQueue = new Queue();

System.out.println("Filling Stack:");

double value;

for (int s = 1; s < 11; ++s)

{

value = s + s/10.0;

System.out.println("\tpushing " + value);

myStack.push(value);

}

System.out.println(" Stack Dump:");

myStack.stackDump();

System.out.println(" Emptying Stack:");

while(!myStack.isEmpty())

{

value = myStack.pop();

System.out.println("\tpop = " + value);

}

System.out.println(" Stack Dump:");

myStack.stackDump();

System.out.println(" A pop too far = " + myStack.pop());

System.out.println(" ");

System.out.println("Filling Queue:");

for (int q = 1; q < 11; ++q)

{

value = 2*q + q/10.0;

System.out.println("\tqueing " + value);

myQueue.que(value);

}

System.out.println(" Queue Dump:");

myQueue.queueDump();

System.out.println(" Emptying Queue:");

while(!myQueue.isEmpty())

{

value = myQueue.deQue();

System.out.println("\tdeQue = " + value);

}

System.out.println(" Queue Dump:");

myQueue.queueDump();

System.out.println(" A deQue too far = " + myQueue.deQue());

}

}

__________________________________________

And produce the following output (or something equivalent):

Filling Stack:

pushing 1.1

pushing 2.2

pushing 3.3

pushing 4.4

pushing 5.5

pushing 6.6

pushing 7.7

pushing 8.8

pushing 9.9

pushing 11.0

Stack Dump:

11.0

9.9

8.8

7.7

6.6

5.5

4.4

3.3

2.2

1.1

Emptying Stack:

pop = 11.0

pop = 9.9

pop = 8.8

pop = 7.7

pop = 6.6

pop = 5.5

pop = 4.4

pop = 3.3

pop = 2.2

pop = 1.1

Stack Dump: A pop too far = NaN

Filling Queue:

queing 2.1

queing 4.2

queing 6.3

queing 8.4

queing 10.5

queing 12.6

queing 14.7

queing 16.8

queing 18.9

queing 21.0

Queue Dump:

array.at(0) = 2.1

array.at(1) = 4.2

array.at(2) = 6.3

array.at(3) = 8.4

array.at(4) = 10.5

array.at(5) = 12.6

array.at(6) = 14.7

array.at(7) = 16.8

array.at(8) = 18.9

array.at(9) = 21.0

Emptying Queue:

deQue = 2.1

deQue = 4.2

deQue = 6.3

deQue = 8.4

deQue = 10.5

deQue = 12.6

deQue = 14.7

deQue = 16.8

deQue = 18.9

deQue = 21.0

Queue Dump:

A deQue too far = NaN

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions

Question

Contrast intelligence and emotional intelligence.

Answered: 1 week ago