Advertisement
Bsantos23

Vetor

Oct 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.95 KB | None | 0 0
  1. package ficticiaLimitada;
  2.  
  3. /**
  4.  * @Author: Breno A. Santos
  5.  *
  6.  * @Descripton:
  7.  * Esta classe implementa a estrutura de dados
  8.  * array (vetor) para guardar as referencias desejadas,
  9.  * alem de metodos usados para manipular os dados nele
  10.  * armazenados.
  11.  */
  12.  
  13. public class Vetor {
  14.  
  15.   /** Atributos */
  16.   private Funcionario[] employee;
  17.   private int contaPosicoesOcupadas = 0;
  18.  
  19.   /** Construtores */
  20.   public Vetor(int tamanho) {
  21.     this.employee = new Funcionario[ tamanho ];
  22.   }
  23.  
  24.  
  25.   /**
  26.    * Metodos
  27.    */
  28.  
  29.  
  30.   // Retorna a primeira posicao vazia do vetor
  31.   public int retornaPosicaoLivre() {
  32.  
  33.     boolean achou = false;
  34.     int indexLivre = -1; // Define -1 para controle de cadastro
  35.  
  36.     for( int i = 0; i < this.employee.length && achou == false; i++ ) {
  37.  
  38.       if( this.employee[ i ] == null ) {
  39.  
  40.         achou = true;
  41.         indexLivre = i;
  42.  
  43.       } // fim do if
  44.  
  45.     } // fim do for
  46.  
  47.     return indexLivre;
  48.   }
  49.  
  50.  
  51.   public boolean cadastra(Funcionario newEmployee) {
  52.  
  53.     int posicaoLivre;
  54.     boolean retorno = false;
  55.    
  56.     posicaoLivre = retornaPosicaoLivre();
  57.    
  58.     if( posicaoLivre > -1 ) {
  59.  
  60.         this.employee[ posicaoLivre ] = newEmployee;
  61.         retorno = true; // Verdadeiro para cadastro realizado
  62.         this.contaPosicoesOcupadas++;
  63.  
  64.     }
  65.    
  66.     return retorno;
  67.   }
  68.  
  69.  
  70.   /** Metodo para alteracao de horas trabalhadas */
  71.   public boolean alteraHoras(int id_funcionario, double new_qt_horas) {  
  72.       boolean achou = false;
  73.       boolean retorno = false;
  74.      
  75.       for( int i = 0; i < this.employee.length && achou == false; i++ ) {
  76.           if( id_funcionario == i ) {
  77.               this.employee[ i ].setHoras(new_qt_horas);
  78.               achou = true;
  79.               retorno = true;
  80.           }
  81.       }
  82.      
  83.       return retorno;
  84.   } // fecha alteraHoras()
  85.  
  86.  
  87.   /** Faz o calculo do salario */
  88.   public double calculaSalario(double qt_horas, char categoria) {
  89.  
  90.     double salario_parcial;
  91.     double acrescimo;
  92.     double salario_bruto = 0;
  93.  
  94.     // Compara e entra na categoria
  95.     if( categoria == 'G' ) {
  96.  
  97.       salario_parcial = qt_horas * 112;
  98.       acrescimo = (salario_parcial * 15) /100; // Aplica um acrescimo de 15% sobre o salario parcial
  99.       salario_bruto = salario_parcial + acrescimo;
  100.      
  101.     } else {
  102.  
  103.       if( categoria == 'O' ) {
  104.  
  105.         salario_parcial = qt_horas * 112;
  106.         acrescimo = (salario_parcial * 10) /100;
  107.         salario_bruto = salario_parcial + acrescimo;
  108.        
  109.       }
  110.  
  111.     } // fecha o if/else
  112.  
  113.     return salario_bruto;
  114.   } // fecha calculaSalario()
  115.  
  116.  
  117.   // Retorna todos os valores do vetor
  118.   public String toString() {
  119.     String retorno = null;
  120.  
  121.     for( int i = 0; i < this.contaPosicoesOcupadas; i++ ) {
  122.       retorno += "\n## ID :: " + i + this.employee[ i ].toString() + "\n> Salario ...............: R$ " + calculaSalario(this.employee[ i ].getHoras(), this.employee[ i ].getCategoria()) + "\n";
  123.     }
  124.  
  125.     return retorno;
  126.   } // fecha toString()
  127.  
  128. } // fecha a classe Vetor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement