-2

So I was given the task to create a very simple Netflix based program. So essentially it has to have a few different classes. A movie class (with basic movie info, already done this though) and a user class (this has to have basic user info like name and account number. but also must have a movie list that displays the five most recently watched movies, and a playlist or essentially a Queue that has the next movies they are going to watch) This is where I am stuck currently, because I do not know enough about Queues to make one for this project. So how would I go about creating a queue for this?

Max Shmelev
  • 3,774
  • 4
  • 26
  • 26
sean flannery
  • 49
  • 1
  • 1
  • 8
  • See [How do I instantiate a Queue object in java?](http://stackoverflow.com/questions/4626812/how-do-i-instantiate-a-queue-object-in-java) – Matt Burland Nov 17 '12 at 21:41

2 Answers2

1

A Queue is a first in, first out (FIFO) data structure. You can just add objects of your Movie class to the Queue and retrieve them as you want. Check out the Queue API.

Also, here is the Oracle/Sun tutorial for using Queues.

asteri
  • 11,402
  • 13
  • 60
  • 84
0

A Queue is a data structure that uses the FIFO format. In the Java API a Queue is an interface which you can either implement yourself, or use an object such as a LinkedList which does it for you. Here is some sample code which should show you one way to use an ArrayDeque as a Queue.

import java.util.ArrayDeque;
import java.util.Queue;


public class QueueTest {

    public static void main(String args[]){

        Queue myQ = new ArrayDeque();

        myQ.add("movie one");
        myQ.add("movie two");
        myQ.add("movie three");

        while(myQ.peek() != null){
            //Movies will be printed in the order they were inserted
            System.out.println(myQ.remove());
        }
    }
}
thedan
  • 1,230
  • 2
  • 9
  • 13