Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a first in first out order class in java with following methods. public FifoList() The default constructor for the FifoList class, which will initialize

Create a first in first out order class in java with following methods.

public FifoList()

The default constructor for the FifoList class, which will initialize maxSize to 0 and the int array to null.

- public FifoList(int maxSize)

The constructor for the FifoList class which takes the int input maxSize to initialize the size of the array. You should NOT reinitialize the array elsewhere. For example, creating an object as new FifoList(5) should create a FifoList whose maximum size is 5. If the parameters passed are invalid (negative numbers) then initialize your class variables maxSize to 0 and the integer array to null.

public FifoList(FifoList q)

The deep copy constructor for the FifoList class, which takes the FifoList object q as an input and creates a deep copy of the FifoList. If the parameters passed are invalid (null object), then initialize your class variables maxSize to 0 and the integer array to null.

- public void add(int element)

A method to add an int element to the FifoList. If FifoList is already full or FifoList is null, print the contents of the MAX_SIZE_ERROR string and return.

public int delete()

A method to delete the top element. Since elements in FifoList are maintained in FIFO order, this method should delete the first element that was inserted into the FifoList and return it. If FifoList is empty or FifoList is null, print the contents of EMPTY_ERROR and return -1.

- public int peek()

A method that returns the top element. Since elements in FifoList are maintained in FIFO order, this method should return the first element that was inserted into the FifoList. If FifoList is empty or FifoList is null, print the contents of EMPTY_ERROR and return -1.

public int size()

A method that returns the size of the FifoList based on how many elements have been added.

public String toString()

A method to print the FifoList as a string in the specified format. Since elements are stored in FIFO order, this method should return string where elements are in FIFO order. If FifoList is empty or FifoList is null, this method should return an empty string. For example:

if the FifoList has elements 2,5,4 (in the order they are inserted), it should return: 2-5-4 If 6 is added to the FifoList and if the toString() method is called, it should return: 2-5-4-6

Tests:

Creating FifoList of maxSize 5 and adding 2, then 7, and then 4: 2, 7, 4 Add 5 to the FifoList: 2, 7, 4, 5 Peek operation (returns the top element): Since FifoList maintains elements in FIFO order, the top element is 2. Hence, returns 2. Delete operation (deletes the top element): 7, 4, 5

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

The Database Experts Guide To SQL

Authors: Frank Lusardi

1st Edition

0070390029, 978-0070390027

More Books

Students also viewed these Databases questions

Question

When do courts grant specific performance as a remedy?

Answered: 1 week ago

Question

How do companies manage the maturity structure of their debt?

Answered: 1 week ago

Question

4. Describe the role of narratives in constructing history.

Answered: 1 week ago

Question

1. Identify six different types of history.

Answered: 1 week ago