import java.io.*;

/**
  * Il programma stampa a video il contenuto di una matrice in una scacchiera
  *
  * @author Roberto Sassi
  * @version 1.0
  *
  */
public class EsempioScacchiera {

  public static void main(String[] args) throws IOException {
    Scacchiera esempio = new Scacchiera();
    InputStreamReader flussoTesto = new InputStreamReader(System.in);
    BufferedReader bufferTastiera = new BufferedReader(flussoTesto);
    String lineaLetta = "";
   
    while(lineaLetta.length() == 0) {
		  esempio.riempiCasualmente();
		
  		// Stampa righe vuote solo per allineare verticalmente le varie stampe
	  	System.out.print("\n");
		  esempio.stampa();
  		// Stampa righe vuote solo per allineare verticalmente  le varie stampe
	  	System.out.print("\n\n");

      System.out.print("Cosa faccio? Premi ENTER per una nuova scacchiera. > ");
      lineaLetta = bufferTastiera.readLine();
   	}	
  }

}

class Scacchiera {
  private char[][] matriceElementi;

  public static final int NUMERO_RIGHE = 10;
  public static final int NUMERO_COLONNE = 12;

  public Scacchiera() {
    this.matriceElementi = new char[NUMERO_RIGHE][NUMERO_COLONNE];
    for(int i=0; i<NUMERO_RIGHE; i++)
      for(int j=0; j<NUMERO_COLONNE; j++)
        this.matriceElementi[i][j]=' ';
  }

  public void setElemento(int riga, int colonna, char valore) {
    this.matriceElementi[riga][colonna] = valore;
  }

  public char getElemento(int riga, int colonna) {
    return this.matriceElementi[riga][colonna];
  }

  public void stampa() {
    // prima una riga in alto
    for(int j=0; j<NUMERO_COLONNE; j++) {
        System.out.print("----");
    }
    System.out.print("-\n");

  	// poi ciascuna riga della matrice
    for(int i=0; i<NUMERO_RIGHE; i++) {
    	for(int j=0; j<NUMERO_COLONNE; j++) {
		    System.out.print("| " + this.matriceElementi[i][j] + " ");
      }
		  System.out.print("|\n");
  		if(i != NUMERO_RIGHE-1) {
    		for(int j=0; j<NUMERO_COLONNE; j++) {
		    	System.out.print("|---");
        }
  			System.out.print("|\n");
  		}		
	  }	
	
	  // e infine la base
	  for(int j=0; j<NUMERO_COLONNE; j++) {
	    System.out.print("----");
	  }
	  System.out.print("-\n");
  }

  public void riempiCasualmente() {
    double numeroCasuale;
    
    // La scacchiera viene inizializzata casualmente ad uno dei tre
    // valori '@', '*' o ' '
    for(int i=0; i<NUMERO_RIGHE; i++)
    	for(int j=0; j<NUMERO_COLONNE; j++)	{
		    numeroCasuale=Math.random();
		    if(numeroCasuale < 0.33)
		    	this.matriceElementi[i][j]='@';
  			else if(numeroCasuale >= 0.66)
  				this.matriceElementi[i][j]='*';
			  else 
				  this.matriceElementi[i][j]=' ';
		  }    
  }

}
  

