Problem row with priority

Asked

Viewed 573 times

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 must be attended to every 3 people with priority password

  • With no priorities, people with normal password can be served

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

1 answer

3


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

FIFO

In Computer Science, FIFO (acronym for First In, First Out, which in Portuguese means first to enter, first to exit) refers to queued type data structures.

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

After that implement the methods to get 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;
}
  • 4

    @TMC you approved a code change, do you realize that only the author can evaluate whether it’s right or not? Avoid approving this type of editing, only the author can decide whether it is valid or not.

  • 4

    @Since you approved a code change, you realize that only the author can evaluate whether it is right or not? Avoid approving this type of editing, only the author can decide whether it is valid or not.

  • 2

    @Articuno makes sense not being able to approve code edits, I’ll get more attention

Browser other questions tagged

You are not signed in. Login or sign up in order to post.