Modeling the queues at a college restaurant

In summary, the conversation discusses the implementation of a code using Java Priority Queues and Maps to identify customers by their arrival time and grades. However, the code is returning an error related to casting and the conversation ends with a request for help. The expert suggests changing the code to add a Customer object instead of a SimpleEntry object to the priority queue.
  • #1
JessicaHelena
188
3
Homework Statement
Here are the constraints: The restaurant runs from 6am to 11:59 pm daily (hence opens at minute 360).

On average, a customer arrives at the restaurant every 5 minutes. (Hence 20% chance of a customer in one minute.)

The restaurant requires between 2 and 7 minutes to fill a customer order, and because there is only one person running the entire restaurant, the next customer in line will be served only after the food is served to the previous customer.

While the restaurant tries to serve everyone in the order they came in, some groups of people are given a priority. Seniors will be served before Juniors; juniors before sophomores; sophomores before freshmen.
Relevant Equations
None specifically.
So far, I have implemented the code below, using Java Priority Queues and Maps. I tried to identify each customer by the time they came in (ranging from 360 and onwards) and their grades. However, this is my first time using priority queues and maps, and I am not very sure if I'm doing things right—in fact, it returns this error below, which I'm not sure how to fix despite having consulted the APIs and some other java resources:

Exception in thread "main" java.lang.ClassCastException: java.base/java.util.AbstractMap$SimpleEntry cannot be cast to java.base/java.lang.Comparable
Below is my code:
Java:
import java.util.*;
import java.util.PriorityQueue;
import java.util.Comparator;
import java.util.Map;

class CustomerComparator implements Comparator<Customer>
{
   public int compare(Customer c1, Customer c2)
   {
      if(c1.grade < c2.grade)
         return 1;
      else if(c1.grade > c2.grade)
         return -1;
      else
         return 0; 
   }
}

class Customer
{
   public int grade;
   public double waitingTime;
  
   public Customer(int grade, double waitingTime)
   {
      this.grade = grade;
      this.waitingTime = waitingTime;
   }
  
   public int getGrade()
   {
      return grade;
   }
  
   public double getWaitingTime()
   {
      return waitingTime;
   }
}

public class McRonaldPriority
{
   public static Queue<Map.Entry<Integer, Integer>> McRonald = new PriorityQueue<Map.Entry<Integer, Integer>>();
   public static int waitingTime = 2 + (int)(Math.random() * ((7 - 2) + 1));
  
   public static void main(String[] args)
   {
      McRonaldsPriority();
   }
  
   public static void McRonaldsPriority()
   {
      double rand = 0.0;
      boolean newCustomer = false;
      for(int i = 360; i<1440; i++)
      {
         if(McRonald.isEmpty())
            waitingTime = 2 + (int)(Math.random() * ((7 - 2) + 1));
         if(i == 1439)
         {
            while(!McRonald.isEmpty())
            {
               waitingTime--;
               if(waitingTime == 0)
               {
                  McRonald.remove();
                  waitingTime = 2 + (int)(Math.random() * ((7 - 2) + 1));
               }
               System.out.println(i + ": " + McRonald);
               i++;
            }
         }
         rand = Math.random();
         if(rand >= 0.0 && rand < 0.2)
            newCustomer = true;
         else
            newCustomer = false;
         if(newCustomer)
         {
            int grade = 0;
            double rand2 = Math.random();
            if(rand >= 0.0 && rand < 0.25)
               grade = 1;
            else if(rand >= 0.25 && rand < 0.5)
               grade = 2;
            else if(rand >= 0.5 && rand <0.75)
               grade = 3;
            else
               grade = 4;
            McRonald.add(new AbstractMap.SimpleEntry(grade,i));
         }
            
         if(!McRonald.isEmpty())
         {
            waitingTime--;
            if(waitingTime == 0)
               McRonald.poll();
         }
         if(!McRonald.isEmpty() && waitingTime == 0)
         {
            waitingTime = 2 + (int)(Math.random() * ((7 - 2) + 1));
         }
         if (i<1439)
            System.out.println(i + ": " + McRonald);
      }
   }
}

I've been stuck on this for a few days, and I'd really like some help!

 
Physics news on Phys.org
  • #2
This apparently is the line of code that's throwing the exception:
Java:
McRonald.add(new AbstractMap.SimpleEntry(grade,i));
Your priority queue is a collection of Customer objects, so I would see if this change works:
Java:
McRonald.add(new Customer(grade, (double)i));
 

1. What is queue modeling and why is it important?

Queue modeling is the process of using mathematical and statistical techniques to analyze and predict the behavior of queues or waiting lines. In the context of a college restaurant, it involves studying the patterns and flow of customers in order to optimize efficiency and reduce wait times. It is important because long wait times can lead to customer dissatisfaction and loss of revenue, while an efficient queue can improve customer experience and increase profits.

2. What types of data are needed for queue modeling at a college restaurant?

Data needed for queue modeling at a college restaurant may include the number of customers entering the restaurant, the time they enter, the time they spend in line, the time they spend at the counter, and the time they spend waiting for their food. Other relevant data may include peak hours, menu items ordered, and any unexpected events that may affect customer flow.

3. How can queue modeling be used to improve the efficiency of a college restaurant?

Queue modeling can be used to optimize the number of servers and cashiers needed at different times of the day, as well as the layout and design of the restaurant to improve the flow of customers. It can also help identify bottlenecks and areas for improvement, such as implementing a self-service kiosk or mobile ordering system.

4. What are some challenges in modeling the queues at a college restaurant?

One challenge is accurately predicting customer behavior, as it can be influenced by various factors such as weather, events, and holidays. Another challenge is obtaining accurate and sufficient data, as it may require extensive observation and data collection. Additionally, the complex and dynamic nature of a college environment may make it difficult to apply traditional queue modeling techniques.

5. How can the results of queue modeling be validated and implemented in a college restaurant?

The results of queue modeling can be validated by comparing them to real-world data and conducting experiments to test the effectiveness of proposed changes. To implement the results, a college restaurant can make adjustments to staffing, layout, and processes based on the findings. Regular monitoring and review of the queue system can also help to continuously improve efficiency and customer satisfaction.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
995
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
18
Views
1K
  • Programming and Computer Science
Replies
1
Views
752
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
944
Back
Top