Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

just part c please Question 5 (30 pts total) You will implement Stack and Queue classes in Java using an ArrayList of Objects. Since java

image text in transcribed

just part c please

Question 5 (30 pts total) You will implement Stack and Queue classes in Java using an ArrayList of Objects. Since java already has Stack and Queue classes, you can call your classes myStack and myQueue. Submit your program files with this assignment. Only submit those ending with (java). Do not submit (class) files. Be sure to add your name at the top of each file. (a) (10 pts) Implement your own Stack class called "myStack" in java. Your class should include the following methods: Object popO: returns and removes the elements on the top of the stack. A 'NoSuchElement Ex- ception' is thrown if pop is called on an empty stack. Object peek(): returns the element on the top of the stack without removing it. A 'NoSuchele. mentException' is thrown if peek is called on an empty stack push(Object: element): pushes the element onto the stack boolean isEmpty(); returns true if no elements are present in the stack, else returns false. int size(): returns the number of items in the stack (b) (10 pts) Implement your own Queue class called "myQueue" in Java. Your class should include the following methods: enqueue(Object: element): add an element to the queue Object front(); returns the head element of the queue without removing it. A 'NoSuchElementEx- ception' is thrown if front is called on an empty queue. Object dequeue(): returns and removed the head of the queue. A 'NoSuch ElementException' is thrown if dequeue is called on an empty queue. boolean isEsmptyO: returns true if no elements are present in the queue, else return false. int size(): returns the number of items in queue (C) (10 pts) Write a short program called "test.java" to verify the function of your Stack and Queue classes. This program will accept a string from the command line (Ex: 1 2 3 4 5). You can assume that the string will be in the form of numbers separated by a single space. You will insert all these numbers (from left to right as given in the string) into both your stack and queue. Then remove and print all elements in the order they are removed from both structures. Once the structures are empty, print the following: "The Stack/Queue is empty". Your program should not throw any of the exceptions listed above. Example output: 54321 The Stack is empty 12345 The Queue is empty

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

Step: 3

blur-text-image

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

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

More Books

Students also viewed these Databases questions

Question

7. Provide appropriate remediation when students fail.

Answered: 1 week ago