Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Ala {
- Random rand = new Random(); // Funçao pra criar numero random (vou usar pra preferencia dos espectadores)
- public static int[][] assentos = new int[2][40]; // Lista de assentos, 2 filas de 40
- int y0=0, y1=0;
- public Ala() {
- for (int i=0; i<80; i++) // loop pra criar 80 espectadores
- {
- int n = rand.nextInt(3); // Numero random de 0 a 2 (3 opçoes)
- Espectador espect = new Espectador(i, n); // cria um espectador espect de id *I* e preferencia *N*
- if (n==0 && y0<40) { // Verifica se ele prefeza ZERO e se a fila ZERO tem vaga
- assentos[0][y0] = espect.id; // Se sim, coloca na fila zero
- y0++; // Incremente 1 na fila zero, pois 1 lugar foi ocupado
- }
- else if (n==1 && y1<40) { // Verifica se ele prefere UM e se a fila UM tem vaga
- assentos[1][y1] = espect.id; // Se sim, coloca na fila UM
- y1++; // Incremente 1 na fila UM, pois 1 lugar foi ocupado
- }
- else { // Caso náo entre nas anteriores
- if (y0 > y1) { // Verifica Se a fila ZERO esta mais ocupada que a fila UM
- assentos[1][y1] = espect.id; // Se sim, coloca na fila UM
- y1++; // Incremente 1 na fila UM, pois 1 lugar foi ocupado
- }
- else { // Caso a fila UM esteja mais ocupada que a fila ZERO
- assentos[0][y0] = espect.id; // Se sim, coloca na fila ZERO
- y0++; // Incremente 1 na fila ZERO, pois 1 lugar foi ocupado
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement