Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.78 KB | None | 0 0
  1. package Geral;
  2.  
  3.  
  4. public class VetVendedor {
  5.  
  6.  
  7.     private Vendedor[] vet;
  8.     private int nElem;
  9.  
  10.     public VetVendedor(int tam)
  11.     {
  12.         vet = new Vendedor[tam];
  13.         this.nElem=0;
  14.     }
  15.  
  16.  
  17.     public int getNElem ()
  18.     {
  19.         return this.nElem;
  20.     }
  21.  
  22.  
  23.     public Vendedor getVendedor (int pos){
  24.  
  25.         // Retorna o vendedor da posição pos ou null (posição inválida)   
  26.         if(pos >0 && pos< nElem)
  27.  
  28.             return vet[pos];
  29.         return null;
  30.     }
  31.  
  32.  
  33.     public int pesquisa (String nome){
  34.  
  35.         // retorna a posição do vendedor que tem o nome passado ou -1 se
  36.         // não encontrar. Feito em sala
  37.  
  38.         for(int i=0; i< nElem; i++){
  39.  
  40.             if(nome.equals(vet[i].getNome()))  //compara o nome passado por argumento
  41.                 //com o getNome;
  42.                 return i;
  43.         }
  44.         return -1;
  45.  
  46.     }
  47.  
  48.  
  49.     public int insere (Vendedor novoVendedor)
  50.     {
  51.         // insere um vendedor no vetor. Se o vetor estiver cheio retorna -1,
  52.         // se o vendedor já foi cadastrado, retorna -2 e se a operação foi
  53.         // bem sucedida, retorna 0. Feito em sala
  54.  
  55.  
  56.         if (this.nElem == this.vet.length)
  57.             return -2;
  58.  
  59.         if(this.pesquisa(novoVendedor.getNome())>= 0)
  60.             return -1;
  61.  
  62.         this.vet[nElem] = novoVendedor;
  63.         this.nElem++;
  64.         return 0;          
  65.     }
  66.  
  67.  
  68.  
  69.  
  70.     public boolean remove (String nome){
  71.         // remove o vendedor solicitado. Se o vendedor não existir, retorna
  72.         // falso. Se a operação for bem sucedida retorna true.
  73.         // Feito em sala.
  74.  
  75.         int pos = this.pesquisa(nome);
  76.  
  77.         if(pos >= 0){
  78.             this.nElem = -1;
  79.             this.vet[pos]= this.vet[this.nElem];
  80.             this.vet[this.nElem]= null;
  81.             return true;
  82.  
  83.         }
  84.  
  85.         return false;
  86.     }
  87.  
  88.  
  89.     // 5 – Fazer um método chamado totalVendas que soma e retorna o total
  90.     // das vendas de todos os seus vendedores de uma categoria que será
  91.     // passada. (1,0)
  92.  
  93.  
  94.  
  95.     public void totalVendas(char categoria)
  96.     {
  97.  
  98.         double somaA = 0.0;
  99.         double somaB = 0.0;
  100.         double somaC = 0.0;
  101.  
  102.         for(int i=0; i< nElem; i++)
  103.         {
  104.  
  105.             if(categoria == 'A')
  106.             {              
  107.                 somaA = somaA + vet[nElem].salario();          
  108.  
  109.             }
  110.  
  111.             if(categoria == 'B')
  112.             {
  113.  
  114.                 somaB = somaB + vet[nElem].salario();  
  115.  
  116.             }
  117.  
  118.             if(categoria == 'C')
  119.             {
  120.  
  121.                 somaC = somaC + vet[nElem].salario();  
  122.  
  123.             }
  124.  
  125.         }
  126.  
  127.         System.out.println( "Categoria A: "+ somaA +
  128.                 "Categoria B: "+ somaB +
  129.                 "Categoria C: "+ somaC);
  130.  
  131.  
  132.     }
  133.  
  134.  
  135.  
  136.  
  137.  
  138.     // 6 - Fazer um método chamado quantVendedores que retorna o total
  139.     // de vendedores de uma categoria que será passada. (1,0)
  140.  
  141.  
  142.  
  143.     /**public int quantVendedores(char categoria)
  144.     {
  145.         int quant;
  146.         int soma = 0;
  147.  
  148.         int i;
  149.  
  150.         categoria = getCategoria();
  151.  
  152.         for(i=0; i< nElem; i++){
  153.  
  154.             if(categoria == 'A')
  155.                 soma = soma +quant;
  156.  
  157.             if(categoria == 'B')
  158.                 soma = soma + quant;
  159.  
  160.             if(categoria=='C')
  161.                 soma = soma + quant;
  162.  
  163.  
  164.         }
  165.         return soma.getCategoria();
  166.     }
  167.  
  168. */
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement