Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. public void cadastrarVenda (Venda venda) throws VendaJaCadastradaException {
  2.         Produto produto = procurarProduto(venda.getVendido());
  3.         if (produto != null) {
  4.             if (produto.getEstoque() > 0) {
  5.                 Funcionario funcionario = (Funcionario)procurarPessoa(venda.getVendedor());
  6.                 if (funcionario != null ) {
  7.                 Cliente cliente = (Cliente)procurarPessoa(venda.getComprador());
  8.                 if (cliente != null) {
  9.                     if(cliente.getSaldo() > produto.getPreco()*1.1) {
  10.                         cliente.setSaldo(cliente.getSaldo()-(produto.getPreco()*1.1));
  11.                         funcionario.receberGorgeta(produto.getPreco()*0.1);
  12.                         cliente.setDinheiroGasto(produto.getPreco()*1.1);
  13.                         funcionario.atenderMesa();
  14.                         produto.retirarEstoque(1);
  15.                         this.vendas.cadastrar(venda);
  16.                     } else if (cliente.getSaldo() > produto.getPreco()) {
  17.                         cliente.setSaldo(cliente.getSaldo()-(produto.getPreco()));
  18.                         cliente.setDinheiroGasto(produto.getPreco());
  19.                         funcionario.atenderMesa();
  20.                         produto.retirarEstoque(1);
  21.                         this.vendas.cadastrar(venda);
  22.                     } else throw new SaldoInsuficienteException();
  23.                 } else throw new PessoaNaoEncontradaException();
  24.                 } else throw new PessoaNaoEncontradaException();
  25.             } else throw new EstoqueInsuficienteException();
  26.         } else throw new ProdutoNaoExisteException();
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement