Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Geral;
- public class VetVendedor {
- private Vendedor[] vet;
- private int nElem;
- public VetVendedor(int tam)
- {
- vet = new Vendedor[tam];
- this.nElem=0;
- }
- public int getNElem ()
- {
- return this.nElem;
- }
- public Vendedor getVendedor (int pos){
- // Retorna o vendedor da posição pos ou null (posição inválida)
- if(pos >0 && pos< nElem)
- return vet[pos];
- return null;
- }
- public int pesquisa (String nome){
- // retorna a posição do vendedor que tem o nome passado ou -1 se
- // não encontrar. Feito em sala
- for(int i=0; i< nElem; i++){
- if(nome.equals(vet[i].getNome())) //compara o nome passado por argumento
- //com o getNome;
- return i;
- }
- return -1;
- }
- public int insere (Vendedor novoVendedor)
- {
- // insere um vendedor no vetor. Se o vetor estiver cheio retorna -1,
- // se o vendedor já foi cadastrado, retorna -2 e se a operação foi
- // bem sucedida, retorna 0. Feito em sala
- if (this.nElem == this.vet.length)
- return -2;
- if(this.pesquisa(novoVendedor.getNome())>= 0)
- return -1;
- this.vet[nElem] = novoVendedor;
- this.nElem++;
- return 0;
- }
- public boolean remove (String nome){
- // remove o vendedor solicitado. Se o vendedor não existir, retorna
- // falso. Se a operação for bem sucedida retorna true.
- // Feito em sala.
- int pos = this.pesquisa(nome);
- if(pos >= 0){
- this.nElem = -1;
- this.vet[pos]= this.vet[this.nElem];
- this.vet[this.nElem]= null;
- return true;
- }
- return false;
- }
- // 5 – Fazer um método chamado totalVendas que soma e retorna o total
- // das vendas de todos os seus vendedores de uma categoria que será
- // passada. (1,0)
- public void totalVendas(char categoria)
- {
- double somaA = 0.0;
- double somaB = 0.0;
- double somaC = 0.0;
- for(int i=0; i< nElem; i++)
- {
- if(categoria == 'A')
- {
- somaA = somaA + vet[nElem].salario();
- }
- if(categoria == 'B')
- {
- somaB = somaB + vet[nElem].salario();
- }
- if(categoria == 'C')
- {
- somaC = somaC + vet[nElem].salario();
- }
- }
- System.out.println( "Categoria A: "+ somaA +
- "Categoria B: "+ somaB +
- "Categoria C: "+ somaC);
- }
- // 6 - Fazer um método chamado quantVendedores que retorna o total
- // de vendedores de uma categoria que será passada. (1,0)
- /**public int quantVendedores(char categoria)
- {
- int quant;
- int soma = 0;
- int i;
- categoria = getCategoria();
- for(i=0; i< nElem; i++){
- if(categoria == 'A')
- soma = soma +quant;
- if(categoria == 'B')
- soma = soma + quant;
- if(categoria=='C')
- soma = soma + quant;
- }
- return soma.getCategoria();
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement