quarta-feira, 22 de fevereiro de 2017

WORLD CUP 2018 - JAVA

Fato é a importância dos arrays Multidimensionais,
que são amplamente utilizados para criar tabelas
onde os elementos são representados por linhas e colunas.
Fácil de criar e utilizar, estes arrays pode ser definido
como cada elemento possuindo outro array armazenado.
Para declará-los, basta criar um novo par de colchetes
logo após o nome dado ao array, não se esquecendo
que a dimensão mais a esquerda representa as linhas
e a da direita representa as colunas.
Sem dúvidas alguma temos como os mais utilizados,
os arrays bidimensionais, e são estes que utilizamos
no nosso programa.
Declarei um array bidimensional de String, inicializado
com os nomes de 32 seleções que participaram da copa
de 2014, embora no título tendo colocado 2018.
E declarei também mais 8 arrays bidimensionais de string,
que receberão cópias do array principal,
cada array deste conjunto de 8, receberão as cópias
de 4 seleções do array principal.
As seleções são chamadas por sorteio, num modo aleatório,
e as impressões na tela são feitas bem posicionadas
para agradar a visão dos interessados pelo programa.

Veja abaixo o vídeo do programa








 Veja abaixo o código do programa

import java.util.Random;

public class PROJETO {
     public static int tam = 32;

     public static int Sorteia ( int vet[] ) {
         J jht = new J ( );
         Random random = new Random ( );
         int i, r, temp;
         for ( i = 0; i < tam; i++ )
              vet [ i ] = i;
         for ( i = 0; i < tam; i++ ) {
              r = random.nextInt ( tam );
              temp = vet [ i ];
              vet [ i ] = vet [ r ];
              vet [ r ] = temp;
         }
         for ( i = 0; i < tam; i++ ) {
              if ( vet [ i ] == 0 ) {
                   vet [ i ] = tam;
              }
         }
         return 0;
     }
     public static int Insere_Aleat ( int vet [ ] ) {
         J jht = new J ( );
         jht.textbackground ( 15 );
         int a = 0, b = 0, c = 0, i, j = 0, k = 0, l = 0, z = 0;
         int a1 = 0, b1 = 0, c1 = 0, d1 = 0, e1 = 0, f1 = 0, g1 = 0, h1 = 0;
         String [ ] [ ] sele_coes_1 = new String [ 4 ] [ 17 ];
         String [ ] [ ] sele_coes_2 = new String [ 4 ] [ 17 ];
         String [ ] [ ] sele_coes_3 = new String [ 4 ] [ 17 ];
         String [ ] [ ] sele_coes_4 = new String [ 4 ] [ 17 ];
         String [ ] [ ] sele_coes_5 = new String [ 4 ] [ 17 ];
         String [ ] [ ] sele_coes_6 = new String [ 4 ] [ 17 ];
         String [ ] [ ] sele_coes_7 = new String [ 4 ] [ 17 ];
         String [ ] [ ] sele_coes_8 = new String [ 4 ] [ 17 ];
         String [ ] [ ] selecoes = {
                   {"Alemanha"       }, //0
                   {"Argélia"        }, //1
                   {"Argentina"      }, //2
                   {"Austrália"      }, //3
                   {"Bélgica"        }, //4
                   {"Bósnia"         }, //5
                   {"Brasil"         }, //6
                   {"Camarões"       }, //7
                   {"Chile"          }, //8
                   {"Colômbia"       }, //9
                   {"Coreia do Sul"  }, //10
                   {"Costa do Marfim"}, //11
                   {"Costa Rica"     }, //12
                   {"Croácia"        }, //13
                   {"Equador"        }, //14
                   {"Espanha"        }, //15
                   {"Estados Unidos "}, //16
                   {"França"         }, //17
                   {"Gana"           }, //18
                   {"Grécia"         }, //19
                   {"Holanda"        }, //20
                   {"Honduras"       }, //21
                   {"Inglaterra"     }, //22
                   {"Irã"            }, //23
                   {"Itália"         }, //24
                   {"Japão"          }, //25
                   {"México"         }, //26
                   {"Nigéria"        }, //27
                   {"Portugal"       }, //28
                   {"Rússia"         }, //29
                   {"Suíça"          }, //30
                   {"Uruguai"       }}; //31
         if ( k == 32 && z >= 1 )
              k = 0;
         jht.gotoxy ( 22, 5 );
         jht.textcolor ( 9 );
         System.out.printf ( "O programa dividirá estas" );
         jht.textcolor ( 12 );
         System.out.printf ( " 32" );
         jht.textcolor ( 9 );
         System.out.printf ( " seleções em" );
         jht.textcolor ( 12 );
         System.out.printf ( " 8" );
         jht.textcolor ( 9 );
         System.out.printf ( " grupos" );
         for ( i = 0; i <= selecoes.length; i++ ) {
              if ( i >= 1 && i <= 16 ) {
                   jht.textcolor ( 12 );
                   jht.gotoxy ( 22, b + 7 );
                   System.out.printf ( "%d", b++ );
                   jht.textcolor ( 9 );
                   jht.gotoxy ( 25, i + 6 );
                   System.out.print ( selecoes [ i - 1 ] [ j ] + " " );
              }
              if ( i >= 17 && i <= 32 ) {
                   jht.textcolor ( 12 );
                   jht.gotoxy ( 52, b - 9 );
                   System.out.printf ( "%d", b++ );
                   jht.textcolor ( 9 );
                   jht.gotoxy ( 55, i - 10 );
                   System.out.print ( selecoes [ i - 1 ] [ j ] + " " );
              }
         }
         jht.textcolor ( 12 );
         jht.gotoxy ( 34, 27 );
         System.out.printf ( "PRESSIONE QUALQUER TECLA" );
         jht.getche ( );
         jht.cls ( );
          //////////////////////////////////////////////////////////////
         jht.textcolor ( 12 );
         jht.gotoxy ( 40, 3 );
         System.out.printf ( "WORLD CUP 2018" );
         for ( i = 0; i < 32; i++ ) {
              k++;
              a = vet [ i ] - 1;
              jht.textcolor ( 12 );
              jht.gotoxy ( 24, 7 );
              System.out.printf ( "%da", k + 0 );
              jht.textcolor ( 9 );
              System.out.printf ( " Seleção sorteada " );
              jht.textcolor ( 12 );
              System.out.print ( selecoes [ a ] [ j ] + " " );
              jht.textcolor ( 9 );
              System.out.printf ( " posição" );
              jht.textcolor ( 12 );
              System.out.printf ( " %d", a );
              jht.textcolor ( 12 );
              jht.gotoxy ( 35, 27 );
              System.out.printf ( "PRESSIONE QUALQUER TECLA" );
              jht.getche ( );
              jht.gotoxy ( 23, 7 );
              jht.Apaga ( 7, 8, 20, 73, 15 );
              if ( k >= 1 && k <= 4 ) {
                   jht.textcolor ( 9 );
                   jht.gotoxy ( 24, 9 );
                   System.out.printf ( "Estamos sorteando as seleções para o grupo" );
                   jht.textcolor ( 12 );
                   System.out.printf ( " A" );
                   if ( k >= 1 || k <= 4 ) {
                        sele_coes_1 [ a1 ] [ l ] = selecoes [ a ] [ j ] + " " ;
                   }
              }
              if ( k >= 5 && k <= 8 ) {
                   jht.textcolor ( 9 );
                   jht.gotoxy ( 24, 9 );
                   System.out.printf ( "Estamos sorteando as seleções para o grupo" );
                   jht.textcolor ( 12 );
                   System.out.printf ( " B" );
                   if ( k >= 5 || k <= 8 ) {
                        sele_coes_2 [ b1 ] [ l ] = selecoes [ a ] [ j ] + " " ;
                   }
              }
              if ( k >= 9 && k <= 12 ) {
                   jht.textcolor ( 9 );
                   jht.gotoxy ( 24, 9 );
                   System.out.printf ( "Estamos sorteando as seleções para o grupo" );
                   jht.textcolor ( 12 );
                   System.out.printf ( " C" );
                   if ( k >= 9 || k <= 12 ) {
                        sele_coes_3 [ c1 ] [ l ] = selecoes [ a ] [ j ] + " " ;
                   }
              }
              if ( k >= 13 && k <= 16 ) {
                   jht.textcolor ( 9 );
                   jht.gotoxy ( 24, 9 );
                   System.out.printf ( "Estamos sorteando as seleções para o grupo" );
                   jht.textcolor ( 12 );
                   System.out.printf ( " D" );
                   if ( k >= 13 || k <= 16 ) {
                        sele_coes_4 [ d1 ] [ l ] = selecoes [ a ] [ j ] + " " ;
                   }
              }
              if ( k >= 17 && k <= 20 ) {
                   jht.textcolor ( 9 );
                   jht.gotoxy ( 24, 9 );
                   System.out.printf ( "Estamos sorteando as seleções para o grupo" );
                   jht.textcolor ( 12 );
                   System.out.printf ( " E" );
                   if ( k >= 17 || k <= 20 ) {
                        sele_coes_5 [ e1 ] [ l ] = selecoes [ a ] [ j ] + " " ;
                   }
              }
              if ( k >= 21 && k <= 24 ) {
                   jht.textcolor ( 9 );
                   jht.gotoxy ( 24, 9 );
                   System.out.printf ( "Estamos sorteando as seleções para o grupo" );
                   jht.textcolor ( 12 );
                   System.out.printf ( " F" );
                   if ( k >= 21 || k <= 24 ) {
                        sele_coes_6 [ f1 ] [ l ] = selecoes [ a ] [ j ] + " " ;
                   }
              }
              if ( k >= 25 && k <= 28 ) {
                   jht.textcolor ( 9 );
                   jht.gotoxy ( 24, 9 );
                   System.out.printf ( "Estamos sorteando as seleções para o grupo" );
                   jht.textcolor ( 12 );
                   System.out.printf ( " G" );
                   if ( k >= 25 || k <= 28 ) {
                        sele_coes_7 [ g1 ] [ l ] = selecoes [ a ] [ j ] + " " ;
                   }
              }
              if ( k >= 29 && k <= 32 ) {
                   jht.textcolor ( 9 );
                   jht.gotoxy ( 24, 9 );
                   System.out.printf ( "Estamos sorteando as seleções para o grupo" );
                   jht.textcolor ( 12 );
                   System.out.printf ( " H" );
                   if ( k >= 29 || k <= 32 ) {
                        sele_coes_8 [ h1 ] [ l ] = selecoes [ a ] [ j ] + " " ;
                   }
              }
         ////////////////////////////////////////////////////////////////////////
              if ( k >= 1 && k <= 4 ) {
                   jht.textcolor ( 9 );
                   jht.gotoxy ( 6, 11 );
                   System.out.printf ( "GRUPO" );
                   jht.textcolor ( 12 );
                   System.out.printf ( " A" );
                   jht.textcolor ( 12 );
                   jht.gotoxy ( 5, k + 12 );
                   System.out.printf ( "%d° ", k + 0 );
                   jht.textcolor ( 9 );
                   System.out.print ( sele_coes_1 [ a1 ] [ l ]  );
              }
              if ( k >= 5 && k <= 8 ) {
                   jht.textcolor ( 9 );
                   jht.gotoxy ( 6, 18 );
                   System.out.printf ( "GRUPO" );
                   jht.textcolor ( 12 );
                   System.out.printf ( " B" );
                   jht.textcolor ( 12 );
                   jht.textcolor ( 12 );
                   jht.gotoxy ( 5, k + 15 );
                   System.out.printf ( "%d° ", k - 4 );
                   jht.textcolor ( 9 );
                   System.out.print ( sele_coes_2 [ b1 ] [ l ]  );
              }
              if ( k >= 9 && k <= 12 ) {
                   jht.textcolor ( 9 );
                   jht.gotoxy ( 26, 11 );
                   System.out.printf ( "GRUPO" );
                   jht.textcolor ( 12 );
                   System.out.printf ( " C" );
                   jht.textcolor ( 12 );
                   jht.gotoxy ( 25, k + 4 );
                   System.out.printf ( "%d° ", k - 8 );
                   jht.textcolor ( 9 );
                   System.out.print ( sele_coes_3 [ c1 ] [ l ]  );
              }
              if ( k >= 13 && k <= 16 ) {
                   jht.textcolor ( 9 );
                   jht.gotoxy ( 26, c + 18 );
                   System.out.printf ( "GRUPO" );
                   jht.textcolor ( 12 );
                   System.out.printf ( " D" );
                   jht.textcolor ( 12 );
                   jht.gotoxy ( 25, k + 7 );
                   System.out.printf ( "%d° ", k - 12 );
                   jht.textcolor ( 9 );
                   System.out.print ( sele_coes_4 [ d1 ] [ l ]  );
              }
              if ( k >= 17 && k <= 20 ) {
                   jht.textcolor ( 9 );
                   jht.gotoxy ( 48, 11 );
                   System.out.printf ( "GRUPO" );
                   jht.textcolor ( 12 );
                   System.out.printf ( " E" );
                   jht.textcolor ( 12 );
                   jht.gotoxy ( 47, k - 4 );
                   System.out.printf ( "%d° ", k - 16 );
                   jht.textcolor ( 9 );
                   System.out.print ( sele_coes_5 [ e1 ] [ l ]  );
              }
              if ( k >= 21 && k <= 24 ) {
                   jht.textcolor ( 9 );
                   jht.gotoxy ( 48, 18 );
                   System.out.printf ( "GRUPO" );
                   jht.textcolor ( 12 );
                   System.out.printf ( " F" );
                   jht.textcolor ( 12 );
                   jht.gotoxy ( 47, k - 1 );
                   System.out.printf ( "%d° ", k - 20 );
                   jht.textcolor ( 9 );
                   System.out.print ( sele_coes_6 [ f1 ] [ l ]  );
              }
              if ( k >= 25 && k <= 28 ) {
                   jht.textcolor ( 9 );
                   jht.gotoxy ( 69, 11);
                   System.out.printf ( "GRUPO" );
                   jht.textcolor ( 12 );
                   System.out.printf ( " G" );
                   jht.textcolor ( 12 );
                   jht.gotoxy ( 68, k - 12 );
                   System.out.printf ( "%d° ", k - 24 );
                   jht.textcolor ( 9 );
                   System.out.print ( sele_coes_7 [ g1 ] [ l ]  );
              }
              if ( k >= 29 && k <= 32 ) {
                   jht.textcolor ( 9 );
                   jht.gotoxy ( 69, 18 );
                   System.out.printf ( "GRUPO" );
                   jht.textcolor ( 12 );
                   System.out.printf ( " H" );
                   jht.textcolor ( 12 );
                   jht.gotoxy ( 68, k - 9 );
                   System.out.printf ( "%d° ", k - 28 );
                   jht.textcolor ( 9 );
                   System.out.print ( sele_coes_8 [ h1 ] [ l ]  );
              }
           ////////////////////////////////////////////////////////////////////
         }// fim do for
         return 0;
    }

     public static void main ( String [ ] args ) {
         J jht = new J ( );
         jht.textbackground ( 15 );
         jht.Moldura ( 1, 29, 2, 88, 15 );
         jht.title ( " " );
         int z = 0, y = 0;
         int vet [ ] = new int [ tam ];
         do {
              jht.cls ( );
         jht.textcolor ( 12 );
         jht.gotoxy ( 40, 3 );
         System.out.printf ( "WORLD CUP 2018" );
              z++;
              jht.textcolor ( 12 );
              jht.gotoxy ( 7, 3 );
              System.out.printf ( "%d°", z + 0 );
              jht.textcolor ( 9 );
              System.out.printf ( " Sorteio" );
              Sorteia ( vet );
              Insere_Aleat ( vet );
              jht.getche ( );
              y++;
         } while ( y < 3 );
         jht.Apaga ( 27, 28, 30, 73, 15 );
         jht.gotoxy ( 30, 27 );
         jht.textcolor ( 9 );
         jht.gotoxy ( 24, 5 );
         System.out.printf ( "O programa realizou os sorteios com sucesso" );
         jht.Sleep ( 1800 );
         jht.textcolor ( 5 );
         jht.gotoxy ( 24, 7 );
         System.out.printf ( "Aprenda a programar em java no meu blog" );
         jht.Sleep ( 1800 );
         jht.textcolor ( 0 );
         jht.gotoxy ( 8, 9 );
         System.out.printf (
                   "http://codigosfontes-ccplus-plus.blogspot.com.br/2016/09/world-cup-2018.html" );
         jht.Sleep ( 1800 );
         jht.textcolor ( 9 );
         jht.gotoxy ( 23, 25 );
         System.out.printf ( "Por: " );
         jht.textcolor ( 5 );
         System.out.printf ( "Samuel Lima" );
         jht.textcolor ( 0 );
         jht.gotoxy ( 23, 26 );
         System.out.printf ( "sa_sp10@hotmail.com" );
         jht.Sleep ( 1800 );
         jht.textcolor ( 12 );
         jht.gotoxy ( 40, 28 );
         System.out.printf ( "MUITO OBRIGADO" );
         jht.getche ( );
     }

}

Nenhum comentário:

Postar um comentário

Observação: somente um membro deste blog pode postar um comentário.