简体   繁体   English

Netflix风格的java程序

[英]Netflix style java program

So I was given the task to create a very simple Netflix based program.所以我的任务是创建一个非常简单的基于 Netflix 的程序。 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?那么我将如何为此创建一个队列?

A Queue is a first in, first out (FIFO) data structure. Queue先进先出 (FIFO)数据结构。 You can just add objects of your Movie class to the Queue and retrieve them as you want.您可以将Movie类的对象添加到Queue并根据需要检索它们。 Check out the Queue API .查看队列 API

Also, here is the Oracle/Sun tutorial for using Queues.此外,这里是使用队列的 Oracle/Sun 教程

A Queue is a data structure that uses the FIFO format.队列是一种使用 FIFO 格式的数据结构。 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.在 Java API 中,队列是一个接口,您可以自己实现它,也可以使用诸如 LinkedList 之类的对象来为您实现。 Here is some sample code which should show you one way to use an ArrayDeque as a Queue.下面是一些示例代码,它应该向您展示使用 ArrayDeque 作为队列的一种方法。

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());
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM