Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use Java to implement a basic stack using an array of integers. For the stack, you will create an array of integers that holds 5

Use Java to implement a basic stack using an array of integers. For the stack, you will create an array of integers that holds 5 numbers. To make it easier, you can declare the array at the class level. That way you will be able to use the array in any method in your class without using parameters.

Your input/output interface should look something like the following:

What operation do you want to do?

push

What number do you want to push?

5

5 has been pushed on the stack

What operation do you want to do?

push

Error: Stack is full

What operation do you want to do? pop

The number popped is 5

What operation do you want to do?

pop

Error: Stack is empty

Variations on the wording are acceptable. But the program needs to acknowledge what number has been pushed or popped. Also, when the user tries to push onto a full stack, the program should print an alert, but otherwise not change the stack. Similarly, if the user tries to pop from an empty stack, the program needs to print an alert, but not change the stack. You will need to implement several methods, including: Push , Pop , Stack Full , Stack Empty Depending on how you structure your program, you may need more methods.

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

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

0764549634, 9780764549632

More Books

Students also viewed these Databases questions