Java 队列场景帮助入门

Java 队列场景帮助入门,java,list,linked-list,queue,simulation,Java,List,Linked List,Queue,Simulation,您好,我目前正在进行队列等待时间模拟,在12小时的过程中,每分钟增加一个随机数,同时每分钟从前面移除三个。12小时后,我将平均他们进出队伍的速度。我需要执行50次才能得到更精确的模型模拟。我目前不知道如何正确地实现这一点。如果我能得到一些关于从哪里开始的建议,我将不胜感激。 链表类 public class LinkedListQueue<E>{ private Node<E> head; private Node<E> tail; private int

您好,我目前正在进行队列等待时间模拟,在12小时的过程中,每分钟增加一个随机数,同时每分钟从前面移除三个。12小时后,我将平均他们进出队伍的速度。我需要执行50次才能得到更精确的模型模拟。我目前不知道如何正确地实现这一点。如果我能得到一些关于从哪里开始的建议,我将不胜感激。 链表类

public class LinkedListQueue<E>{

private Node<E> head;
private Node<E> tail;
private int size;

public LinkedListQueue() {

}

public void enqueue(E element) {
    Node newNode = new Node(element, null);

    if (size == 0) {
        head = newNode;
    } else {
        tail.setNextNode(newNode);
    }

    tail = newNode;
    size++;
}

public E dequeue() {
    if (head != null) {
        E element = head.getElement();
        head = head.getNextNode();
        size--;
        if (size == 0) {
            tail = null;
        }
        return element;
    }
    return null;
}

public E first() {
    if (head != null) {
        return head.getElement();
    }
    return null;
}

public int getSize() {
    return size;
}

public void print() {
    if (head != null) {
        Node currentNode = head;
        do {
            System.out.println(currentNode.toString());
            currentNode = currentNode.getNextNode();
        } while (currentNode != null);
    }
    System.out.println();
}
}
公共类LinkedListQueue{
专用节点头;
私有节点尾部;
私有整数大小;
公共LinkedListQueue(){
}
公共无效排队(E元素){
Node newNode=新节点(元素,空);
如果(大小==0){
头=新节点;
}否则{
tail.setNextNode(newNode);
}
tail=newNode;
大小++;
}
公共E出列(){
if(head!=null){
E元素=head.getElement();
head=head.getNextNode();
大小--;
如果(大小==0){
tail=null;
}
返回元素;
}
返回null;
}
公共电子优先{
if(head!=null){
返回head.getElement();
}
返回null;
}
公共int getSize(){
返回大小;
}
公开作废印刷品(){
if(head!=null){
节点当前节点=头;
做{
System.out.println(currentNode.toString());
currentNode=currentNode.getNextNode();
}while(currentNode!=null);
}
System.out.println();
}
}
节点类

public class Node<E>{
private E element;
private Node<E> next;

public Node(E element, Node next) {
    this.element = element;
    this.next = next;
}

public void setNextNode(Node next) {
    this.next = next;
}

public Node<E> getNextNode() {
    return next;
}

public E getElement() {
    return element;
}

public String toString() {
    return element.toString();
}
}
公共类节点{
私人电子元件;
私有节点下一步;
公共节点(E元素,下一个节点){
this.element=元素;
this.next=next;
}
public void setNextNode(节点下一个){
this.next=next;
}
公共节点getNextNode(){
下一步返回;
}
公共E getElement(){
返回元素;
}
公共字符串toString(){
返回元素.toString();
}
}
模拟班

import java.util.Random;

public class Simulation {

private int arrivalRate;
//you'll need other instance variables

public Simulation(int arrivalRate, int maxNumQueues) {
    this.arrivalRate = arrivalRate;
}

public void runSimulation() {
    //this is an example for using getRandomNumPeople
    //you are going to remove this whole loop.
    for (int i = 0; i < 10; i++) {
        int numPeople = getRandomNumPeople(arrivalRate);
        System.out.println("The number of people that arrived in minute " + i + " is: " + numPeople);
    }
}

//Don't change this method.
private static int getRandomNumPeople(double avg) {
    Random r = new Random();
    double L = Math.exp(-avg);
    int k = 0;
    double p = 1.0;
    do {
        p = p * r.nextDouble();
        k++;
    } while (p > L);
    return k - 1;
}

//Don't change the main method.
public static void main(String[] args) {
    Simulation s = new Simulation(18, 10);
    s.runSimulation();
}
}
import java.util.Random;
公共类模拟{
私人入境者;
//您将需要其他实例变量
公共模拟(int-arrivalRate、int-maxNumQueues){
this.arrivalRate=arrivalRate;
}
公共模拟{
//这是一个使用getRandomNumPeople的示例
//您将删除整个循环。
对于(int i=0;i<10;i++){
int numPeople=getRandomNumPeople(到达率);
System.out.println(“分钟内到达的人数”+i+”为:“+numPeople”);
}
}
//不要改变这个方法。
私有静态int getRandomNumPeople(双平均值){
随机r=新随机();
双L=数学表达式(-avg);
int k=0;
双p=1.0;
做{
p=p*r.nextDouble();
k++;
}而(p>L);
返回k-1;
}
//不要改变主方法。
公共静态void main(字符串[]args){
模拟s=新模拟(18,10);
s、 运行模拟();
}
}

看起来您根本没有开始这项任务

首先,从main()方法开始。将创建一个新的模拟对象。按照构造函数调用新建模拟(18,10)。对于初学者,您将看到构造函数是不完整的

public Simulation(int arrivalRate, int maxNumQueues) {
    this.arrivalRate = arrivalRate;
    // missing the handling of maxNumQueues
}
因此,对于初学者,您可能希望在Simulation类中定义integer类型的新变量(因为根据Simulation构造函数,这是maxNumQueues的类型)。从这里开始,您显然希望返回构造函数并设置新变量以引用构造函数调用

例如:

public class Simulation {

private int arrivalRate;
private int maxNumQueues; // keep track of the maxNumQueues

public Simulation(int arrivalRate, int maxNumQueues) {
    this.arrivalRate = arrivalRate;
    this.maxNumQueues = maxNumQueues; // initialize our new local variable maxNumQueues
}}

是的,我才刚刚开始,这份作业的摘要对于他想要什么非常混乱