Advertisement
alinemtg

o q fiz ate agora ou ao menos tentativa

Jun 23rd, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.94 KB | None | 0 0
  1. // ONEEEE
  2.  
  3. package inferno;
  4.  
  5. public class Venda {
  6.     private Cliente cliente;
  7.     private Livro livro;
  8.     private double total;
  9.  
  10.     public Venda (Cliente cliente, Produto produto, double total) {
  11.         this.Pessoa = pessoa;
  12.         this.livro = livro;
  13.         this.total = calcularTotal(cliente.getPlano(), produto.getPreco());
  14.     }
  15.  
  16.     public double calcularTotal (Integer nivel, double preco) {
  17.         this.total = preco - (nivel*0.05)*preco;
  18.         return total;
  19.     }
  20. }
  21.  
  22. // REPOSITORIO VENDA ARRAY
  23.  
  24. package inferno;
  25.  
  26. public class RepositorioVendaLista {
  27.     package repositorio;
  28.  
  29.     public class RepositorioVendaLista {
  30.         private Venda venda;
  31.         private RepositorioVendaLista prox;
  32.        
  33.         public RepositorioVendaLista() {
  34.             this.venda = null;
  35.             this.prox = null;
  36.         }
  37.        
  38.         public void inserir (Venda venda) {
  39.             if (this.venda == null) {
  40.                 this.venda = venda;
  41.                 this.prox = new RepositorioVendaLista();
  42.             }else {
  43.                 this.proximo.adicionar (venda);
  44.             }
  45.         }
  46.        
  47.         public boolean procurar (Venda venda) {
  48.             if (this.venda != null && this.venda.cliente.getcpf().equals(venda.cliente.getcpf())
  49.                 && this.vendas.total == venda.total) {
  50.                 return true;
  51.             }else if (this.prox.venda != null) {
  52.                 return this.prox.procurar(venda);
  53.             }return false;
  54.         }
  55.            
  56.        
  57.         public void remover (Venda venda) {
  58.             if (this.venda != null && this.venda.cliente.getcpf().equals(venda.cliente.getcpf()
  59.                     && this.venda.total == venda.total)) {
  60.                 this.venda = this.proximo.venda;
  61.                 this.proximo = this.proximo.proximo;
  62.                 System.out.println("Venda retirada com sucesso");
  63.             }else {
  64.                 this.proximo.retirar(venda);
  65.             }
  66.         }
  67.     }
  68.  
  69. }
  70.  
  71.  
  72. // REPOSITORIO VENDA LISTA
  73.  
  74. package inferno;
  75.  
  76. public class RepositorioVendaArray {
  77.         private Venda [] vendas;
  78.        
  79.         public RepositorioVendaArray() {
  80.             vendas = new Venda [3];
  81.         }
  82.        
  83.         public void adicionar (Venda venda) {
  84.             for (int i=0; i < vendas.length; i++) {
  85.                 if (vendas[i] == null) {
  86.                     vendas[i] = venda;
  87.                     System.out.println("Venda adicionada com sucesso");
  88.                     return;
  89.                 }
  90.             }
  91.             Venda[] vendas2 = new Venda [vendas.length * 2];
  92.            
  93.             for (int i=0; i<vendas.length; i++) {
  94.                 vendas2[i] = vendas[i];
  95.             }
  96.             this.vendas = vendas2;
  97.             adicionar(venda);
  98.         }
  99.        
  100.         public boolean procurar (Venda venda) {
  101.         boolean achou = false;
  102.             for (int i=0; i< vendas.length && !achou; i++) {
  103.                 if (this.venda.cliente.getcpf().equals(venda.cliente.getcpf())
  104.                         && this.vendas.total == venda.total) {
  105.                     achou = true;
  106.                 }
  107.             }return achou;
  108.         }
  109.        
  110.         public void remover (Venda venda) {
  111.         for (int i=0; i< vendas.length; i++) {
  112.             if (this.venda.cliente.getcpf().equals(venda.cliente.getcpf())
  113.                     && this.vendas.total == venda.total) {
  114.                 vendas[i] = null;
  115.                
  116.             }
  117.  
  118.         }
  119.            
  120.     }
  121.    
  122. }
  123.  
  124.  
  125. // EXCEPTION
  126.  
  127. package inferno;
  128.  
  129.     public class VendaNaoEncontradaException extends Exception {
  130.         public VendaNaoEncontradaException (Venda venda) {
  131.             super("Venda ainda nao realizada");
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement