Advertisement
CMatchelo

Untitled

Dec 13th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. class Ala {
  2. Random rand = new Random(); // Funçao pra criar numero random (vou usar pra preferencia dos espectadores)
  3. public static int[][] assentos = new int[2][40]; // Lista de assentos, 2 filas de 40
  4. int y0=0, y1=0;
  5. public Ala() {
  6. for (int i=0; i<80; i++) // loop pra criar 80 espectadores
  7. {
  8. int n = rand.nextInt(3); // Numero random de 0 a 2 (3 opçoes)
  9. Espectador espect = new Espectador(i, n); // cria um espectador espect de id *I* e preferencia *N*
  10. if (n==0 && y0<40) { // Verifica se ele prefeza ZERO e se a fila ZERO tem vaga
  11. assentos[0][y0] = espect.id; // Se sim, coloca na fila zero
  12. y0++; // Incremente 1 na fila zero, pois 1 lugar foi ocupado
  13. }
  14. else if (n==1 && y1<40) { // Verifica se ele prefere UM e se a fila UM tem vaga
  15. assentos[1][y1] = espect.id; // Se sim, coloca na fila UM
  16. y1++; // Incremente 1 na fila UM, pois 1 lugar foi ocupado
  17. }
  18. else { // Caso náo entre nas anteriores
  19. if (y0 > y1) { // Verifica Se a fila ZERO esta mais ocupada que a fila UM
  20. assentos[1][y1] = espect.id; // Se sim, coloca na fila UM
  21. y1++; // Incremente 1 na fila UM, pois 1 lugar foi ocupado
  22. }
  23. else { // Caso a fila UM esteja mais ocupada que a fila ZERO
  24. assentos[0][y0] = espect.id; // Se sim, coloca na fila ZERO
  25. y0++; // Incremente 1 na fila ZERO, pois 1 lugar foi ocupado
  26. }
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement