Design and implement a class Queue

computer science

Description

Design and implement a class Queue that supports queues by extending SinglyLinkedList.java (i.e.

your queues are singly­linked­lists). Documentation for SinglyLinkedList.java is its code and

comments that are found in the code.


class Queue must support the following instance methods.

public Queue();

// creates a Q with capacity 8 (the default capacity)

public Queue(int capacity);

public Queue enqueue(Object elem) throws IllegalStateException;

// throw exception if Q is full (i.e. at capacity)

// return "this" to enable chaining

public Object dequeue() throws NoSuchElementException;

// throw exception if Q is empty

public Object front() throws NoSuchElementException;

// throw exception if Q is empty

public int getCapacity();

// return Q's capacity

public void setCapacity(int newcapacity) throws IllegalArgumentException;

// throw exception if capacity less than 0

// if newcapacity < capacity and size > newcapacity,

// then truncate Q to newcapacity

public int size();

// return number of elements in the Q

public boolean isEmpty();

// true if size is zero

public boolean isFull();

// true if size equals capacity

public String toString();

// return a string representation of the Q

The main() method of your program should contain code to test class Queue objects. This program

can use your Menu and MenuItem classes.

Queue Test Menu

===============

1) enqueue

2) dequeue

3) front

4) print

5) get size

6) get capacity

7) set capacity

8) is full?


12/14/2016 CSC205::Assignment::#Queue


9) is empty?

10) Exit


Related Questions in computer science category