Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSCI 143: Object Oriented Programming 2 with Java LinkedList In-class Exercise It is often the case that new data structures are written using other existing

CSCI 143: Object Oriented Programming 2 with Java LinkedList In-class Exercise It is often the case that new data structures are written using other existing data structures as an underlying model. In this practice exercise we will be creating a Queue class using Javas LinkedList as a basis for our new class. A Queue data structure behaves similarly to a set of people waiting in line. There are restrictions on entering and exiting the line: 1. You may only enter the line at the back, referred to as an enqueue operation. 2. You may only exit the line at the front, referred to as a dequeue operation. 3. You may also look at the person in the front of the line, referred to as a peek

operation. 4. You cannot be helped if you are in the middle of the line. Because of these restrictions, a Queue data type is referred to as a FIFO structure (first-in-first-out). Note: because we only allow access to elements at the front/back of a Queue, this removes the index-based access of structures such as Arrays and ArrayLists Write a new Queue class using a LinkedList as the underlying storage structure (in other words, a private instance field). You can simulate the behavior described above by adding items to the front of your LinkedList and removing items from the back. Hint: I would suggest looking for helpful methods in the Java API for the LinkedList class.

In particular the following methods: addFirst, addLast, removeFirst, removeLast

Use the following class diagram as a basis for your class:

Queue

- data : LinkedList

+ enqueue(newElement : T) : void + dequeue() : T + peek() : T + isEmpty() : boolean + size() : int

Note: your Queue class should throw an appropriate exception when dequeue() is called on an empty Queue.

Write a test class to show that your Queue class is working correctly.

CSCI 143: Object Oriented Programming 2 with Java Challenge: create a new class called BoundedQueue that enforces a maximum number of elements in your queue. 1. Use the code from your Queue class as a starting point in your new BoundedQueue class 2. Include only a parameterized constructor that takes a positive integer that specifies the

maximum number of elements in your bounded queue 3. Throw an appropriate exception if you queue size exceeds the bounds given

Error! We couldnt load the file.

Retry?

1 / 2

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

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

10. Provide an adequate debriefing for research participants.

Answered: 1 week ago

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago