Im really stuck on where to begin with this program If anyon

I\'m really stuck on where to begin with this program, If anyone would be able to provide some of the code to get me started, I will be extrememly thankful. Needs to be written in object oriented based Java.

Queue simulation. Write a program that simulates a checkout line in a supermarket. A queue is FIFO, so enqueue at the tail of the queue, and dequeue at the head of the queue. The line will be a queue object array. Customer (objects) will arrive in random intervals from 1 to 4 minutes. Customers remain in the queue until they are serviced – also determined by another random interval from 1 to 4 minutes. The arrival times and the service times are, then, integers between 1 and 4. Run the simulation for 720 minutes (a 12-hour day). Use an algorithm similar to:

a. Choose a random number between 1 and 4 to determine when the first customer arrives. When this time (in minutes) arrives, add a customer to the queue (see also b below), and determine when the next random customer is to arrive.

b. At each customer’s arrival time: 1) determine the customer’s service time (also between 1 and 4 minutes) when reaching the head of the queue, 2) enqueue the customer, and 3) schedule the arrival of the next customer (between 1 and 4 minutes).

c. For each simulated minute of the day:

i. When a customer arrives on the queue: 1) say so, 2) determine the customer’s service time and display it, 3) enqueue the arrival, and 4) schedule the next customer’s arrival time, and display it.

ii. When service is completed for each customer: 1) say so, 2) determine the customer’s completion time (an integer between 1 and 720 – also display this time when you say so), 3) determine the customer’s actual wait time (which is the time now minus the customer’s arrival time), and 3) dequeue the customer.

iii. Note: no butting in line! Only dequeue at the head of the queue, even if there are customers with shorter service times behind the head.

d. At the end of the simulation, display: 1) number of customers serviced in the simulation, 2) the maximum number of customers in the queue during the 720-minute simulation, 3) the average actual wait time for all customers (a double), and 4) the number of customers left on the queue when the simulation ends.

e. Place all output into a file (and post it to Canvas when submitting the assignment). Implement the queue as a LinkedList:

Queue <Customer> q = new LinkedList<Customer>();

Solution

Customer.java

public class Customer{
    int arr_time = 0;
    int arr_count = 0;

    public Customer(int arr_time, int arr_count){
        this.arr_time = arr_time;
        this.arr_count = arr_count;
    }
}

Simulation.java

import java.util.*;

public class Simulation{
    public static void main(String[] args) {
        int t = 0;
        PriorityQueue<Customer> customers = new PriorityQueue<Customer>();
        int arr_count = 0;
        Random generator = new Random();
        int arrival_time = generator.nextInt(4) + 1;
        generator = new Random();
        int departure_time = arrival_time + generator.nextInt(4) + 1;
        int max_wait = 0;
        int max_size = 0;
        int customer_departed;
        int wait_time;
        while (t<720){
            if (arrival_time == t){
                arr_count ++;
                customers.add(new Customer(t, arr_count));
                System.out.println(\"Customer \" + arr_count + \" has arrived\");
                generator = new Random();
                arrival_time = generator.nextInt(4) + 1 + t;
            }

            if (departure_time == t){
                if (customers.size()>0){
                    customer_departed = customers.peek().arr_count;
                    wait_time = t - customers.peek().arr_time;
                    if (wait_time > max_wait){
                        max_wait = wait_time;
                    }

                    customers.poll();
                    System.out.println(\"Service was completed for customer \" + customer_departed);
                    generator = new Random();
                    departure_time = generator.nextInt(4) + t;
                }
            }
            int queue_size = customers.size();
            if (max_size < queue_size){
                max_size = queue_size;
            }
            t++;
        }

        System.out.println(\"Total Number of customers serviced: \" + customers.peek().arr_count);

        System.out.println(\"Maximum number of customers in queue at any time: \" + max_size);

        System.out.println(\"Longest wait any one customer experienced: \" + max_wait);
    }
}

I\'m really stuck on where to begin with this program, If anyone would be able to provide some of the code to get me started, I will be extrememly thankful. Nee
I\'m really stuck on where to begin with this program, If anyone would be able to provide some of the code to get me started, I will be extrememly thankful. Nee

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site