class Guarita {

private int id;
private char tipo;
private int total = 0;

static private int somaTotais = 0;

static private boolean aberta1 = false;
static private boolean aberta2 = false;
static private boolean aberta3 = false;
static private boolean aberta4 = false;

static private int contGrandes = 0;
static private int contPeq = 0;
static private int contMotos = 0;

final static private int maxGrandes = 3;
final static private int maxPeq = 5;
final static private int maxMotos = 3;

final static private int taxaGrandes = 5;
final static private int taxaPeq = 3;
final static private int taxaMotos = 1;


Guarita (int id, char tipo) {
   this.id = id;
   if (tipo != 'e' && tipo != 's') 
       System.out.println("Erro na criação da guarita. Tipo inválido"); 
   else
       this.tipo = tipo; 
}  // Guarita ()

private boolean consultaAberta() {
       boolean b=false;
       switch( this.id ) {
           case 1: b = aberta1; break;
           case 2: b = aberta2; break; 
           case 3: b = aberta3; break;  
           case 4: b = aberta4; break;  };
       return b;
}  // consultaAberta

private void atualizaAberta(boolean b) {
       switch( id ) {
           case 1: aberta1 = b; break;
           case 2: aberta2 = b; break;
           case 3: aberta3 = b; break;
           case 4: aberta4 = b; break;}
}  // atualizaAberta

public void abrir() {
   if (tipo == 'e')
       System.out.println("Guarita G" + id + " em funcionamento.");
   else  
       System.out.println("Saída aberta."); 
   this.atualizaAberta(true);   
}  // abrir()

public void fechar() {
if (tipo == 'e'){
    System.out.println("Fechando a entrada G"+ id +" com total " + total + " reais."); 
    this.atualizaAberta(false);
    somaTotais = somaTotais + this.total; 
}
else 
    if (!aberta1 && !aberta2 && !aberta3) {
        this.atualizaAberta(false);
        System.out.println("Estacionamento fechado. Total do dia: "+ somaTotais +" reais."); }
    else
        System.out.println("Erro: verifique se há alguma entrada em funcionamento");
}  // fechar()

public void receber(Veículo veic) {
   if (this.tipo == 'e' && this.consultaAberta()) 
      if (veic.tipo() == "grande")
         if (contGrandes < maxGrandes ){
            contGrandes = contGrandes + 1;
            total = total + taxaGrandes;
            System.out.println(veic.nome() + " entrando por G"+ id + "."); }
         else
            System.out.println("Não há vagas para este veículo.");
      else 
         if (veic.tipo() == "pequeno")
            if (contPeq < maxPeq ){
               contPeq = contPeq + 1;
               total = total + taxaPeq;
               System.out.println(veic.nome() + " entrando por G"+ id + "."); }
            else
               System.out.println("Não há vagas para este veículo.");
         else
            if (contMotos < maxMotos ){
               contMotos = contMotos + 1;
               total = total + taxaMotos;
               System.out.println(veic.nome() + " entrando por G"+ id + "."); }
            else
               System.out.println("Não há vagas para este veículo.");
}  // receber()

public void liberar(Veículo veic) {
   if (this.tipo == 's' && this.consultaAberta() ) {
      if (veic.tipo() == "grande") contGrandes = contGrandes - 1;
      else 
         if (veic.tipo() == "pequeno") contPeq = contPeq - 1;
         else contMotos = contMotos - 1;
      System.out.println(veic.nome() + " saindo."); }
}  // liberar()

}  // class Guarita