Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ONEEEE
- package inferno;
- public class Venda {
- private Cliente cliente;
- private Livro livro;
- private double total;
- public Venda (Cliente cliente, Produto produto, double total) {
- this.Pessoa = pessoa;
- this.livro = livro;
- this.total = calcularTotal(cliente.getPlano(), produto.getPreco());
- }
- public double calcularTotal (Integer nivel, double preco) {
- this.total = preco - (nivel*0.05)*preco;
- return total;
- }
- }
- // REPOSITORIO VENDA ARRAY
- package inferno;
- public class RepositorioVendaLista {
- package repositorio;
- public class RepositorioVendaLista {
- private Venda venda;
- private RepositorioVendaLista prox;
- public RepositorioVendaLista() {
- this.venda = null;
- this.prox = null;
- }
- public void inserir (Venda venda) {
- if (this.venda == null) {
- this.venda = venda;
- this.prox = new RepositorioVendaLista();
- }else {
- this.proximo.adicionar (venda);
- }
- }
- public boolean procurar (Venda venda) {
- if (this.venda != null && this.venda.cliente.getcpf().equals(venda.cliente.getcpf())
- && this.vendas.total == venda.total) {
- return true;
- }else if (this.prox.venda != null) {
- return this.prox.procurar(venda);
- }return false;
- }
- public void remover (Venda venda) {
- if (this.venda != null && this.venda.cliente.getcpf().equals(venda.cliente.getcpf()
- && this.venda.total == venda.total)) {
- this.venda = this.proximo.venda;
- this.proximo = this.proximo.proximo;
- System.out.println("Venda retirada com sucesso");
- }else {
- this.proximo.retirar(venda);
- }
- }
- }
- }
- // REPOSITORIO VENDA LISTA
- package inferno;
- public class RepositorioVendaArray {
- private Venda [] vendas;
- public RepositorioVendaArray() {
- vendas = new Venda [3];
- }
- public void adicionar (Venda venda) {
- for (int i=0; i < vendas.length; i++) {
- if (vendas[i] == null) {
- vendas[i] = venda;
- System.out.println("Venda adicionada com sucesso");
- return;
- }
- }
- Venda[] vendas2 = new Venda [vendas.length * 2];
- for (int i=0; i<vendas.length; i++) {
- vendas2[i] = vendas[i];
- }
- this.vendas = vendas2;
- adicionar(venda);
- }
- public boolean procurar (Venda venda) {
- boolean achou = false;
- for (int i=0; i< vendas.length && !achou; i++) {
- if (this.venda.cliente.getcpf().equals(venda.cliente.getcpf())
- && this.vendas.total == venda.total) {
- achou = true;
- }
- }return achou;
- }
- public void remover (Venda venda) {
- for (int i=0; i< vendas.length; i++) {
- if (this.venda.cliente.getcpf().equals(venda.cliente.getcpf())
- && this.vendas.total == venda.total) {
- vendas[i] = null;
- }
- }
- }
- }
- // EXCEPTION
- package inferno;
- public class VendaNaoEncontradaException extends Exception {
- public VendaNaoEncontradaException (Venda venda) {
- super("Venda ainda nao realizada");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement