Problem queue with priority

3

Someone gives me a light of what to do to solve this problem, I have no idea how to start

  

Write a program that simulates the distribution of service passwords to a group of people. Each person can receive a priority password or a normal password. The program must meet the following criteria:

     
  • There is only one attendant
  •   
  • 1 person with normal password should be served to every 3 people with priority password

  •   

  •   

I'm not asking for the answer, I just want an explanation of what I have to do

    
asked by anonymous 17.10.2017 / 06:18

1 answer

3

You will need two FIFO lists that Java can be obtained using LinkedList :

  

FIFO

     

In Computer Science, FIFO (acronym for First In, First Out) refers to data structures of the queue type.

LinkedList<String> normal = new LinkedList<>();
LinkedList<String> prioritaria = new LinkedList<>();

After this implement the methods to obtain a priority or normal password:

public String pegarSenhaNormal() {
  String senha = gerarSenha();

  normal.add(senha);
  return senha;
}

public String pegarSenhaPrioritaria() {
  String senha = gerarSenha();

  prioritaria.add(senha);
  return senha;
}

Keep an accountant:

Integer contador = 0;

Implement the method to call the next password with the empty queue rule and counter after the third call:

public String chamarProximo() {
  LinkedList<String> fila;
  String senha;

  if (contador.equals(3) || prioritaria.isEmpty()) {
    fila = normal;
    contador = 0;
  } else {
    fila = prioritaria;
    contador++;
 }

  senha = fila.removeFirst();
  return senha;
}
    
17.10.2017 / 09:00