You are going to build a small game using a linked list queue. You will have a juggler (Stephen) who is using two data structures to juggle (his hands and the air). His hands will be modeled with a simple data structure that holds a single juggling ball at a time, and the air will be modeled as a queue data structure which can hold a several items. The outline has been provided for these classes.
You have been provided with several classes already. Note that if you have completed Part 1, than understanding these classes and the interactions between them should be much easier.
The Hand Class (see Juggler.java)
This is basically a single item list with three methods. Below are some notes on the methods which you may find useful:
public void catchBall(Ball ball)
public Ball throwBall()
public boolean hasBall()
The ListItem< T> Class (see Air.java)
This class should be the building block for a linked list. It needs to contain some private class variables to get it working. Use the getters and setters appropriately.
The Air< T> Class (see Air.java)
This class, as outlined, is a linked list queue. It needs to implement the Queue< T> interface and information about what each of the methods in the class does can be found in the API documentation (http://docs.oracle.com/javase/8/docs/api/java/util/Queue.html). A tutorial on the queue interface can be found here: http://docs.oracle.com/javase/tutorial/collections/interfaces/queue.html. Several methods from this interface have already been written for you (and may not be changed). Eleven other methods (6 required by the Queue interface, and 5 required by the Collection interface) have been outlined for you and need to be implemented. Below are some notes on the methods which you may find useful:
Note: For your purposes, O(1) means that this can be done without a loop, and O(n) means you'll need to loop through all the elements in the list.
public boolean add(T item)
public boolean offer(T item)
public T remove()
public T poll()
public T element()
public T peek()
public String toString()
public void clear()
public boolean isEmpty()
public int size()
public Object toArray()
The Assignment6 Class
This class contains the main code to interact with the juggler. You will need to prompt for input and perform the appropriate actions to produce both the same output as the samples below (as well as any other details covered in class). If you have any questions as to what should be output in specific situations: ASK!
public static void main(String arg)
Unit tests have been provided for this portion of your code (Assignment6SampleTests.java). Additionally, below is some sample output for main:
> java Assignment6 Stephen, the juggler, is learning to do a shower trick...
He has 4 balls
1) Throw a ball into the air
2) Pass a ball between hands
3) Catch a ball from the air