Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Cliente;
- public interface RepositorioCliente {
- void inserir (Cliente cliente) throws RepositorioCheioException;
- void remorer (Cliente cliente) throws ClienteNaoExisteException;
- Cliente procurar (String cpf);
- void atualizar (Cliente cliente) throws ClienteNaoExisteException;
- }
- package Cliente;
- public class RepositorioCheioException extends Exception {
- private Cliente cliente;
- public RepositorioCheioException (Cliente cliente) {
- super ("O cliente" + cliente.getCPF() +"não pois o limite de cadastros foi atingido.");
- this.cliente = cliente;
- }
- }
- package Cliente;
- public class ClienteNaoExisteException extends Exception {
- private Cliente cliente;
- public ClienteNaoExisteException (Cliente cliente) {
- super("O cliente" + cliente.getCPF() + "não existe");
- this.cliente = cliente;
- }
- }
- package Cliente;
- public class RepositorioClienteArray implements RepositorioCliente {
- private Cliente[] clientes;
- private int Indice;
- public RepositorioClienteArray (int tam) {
- clientes = new Cliente[tam];
- this.Indice = 0;
- }
- public void inserir (Cliente cliente) throws RepositorioCheioException {
- if (this.Indice != clientes.length) {
- clientes[this.Indice] = cliente;
- this.Indice++;
- } else throw new RepositorioCheioException(cliente);
- }
- public void remorer (Cliente cliente) throws ClienteNaoExisteException {
- if (procurar(cliente.getCPF()) != null) {
- boolean removeu = false;
- for (int b = 0; b < this.Indice; b++) {
- if (clientes[b].getCPF().equals(cliente.getCPF())) {
- clientes[b] = null;
- removeu = true;
- }
- if (removeu) {
- if (b < this.Indice - 1) {
- clientes[b] = clientes[b + 1];
- }
- }
- }
- this.Indice--;
- } else throw new ClienteNaoExisteException(cliente);
- }
- public Cliente procurar (String cpf) {
- for (int a = 0; a < this.Indice; a++) {
- if (clientes[a].getCPF().equals(cpf)) {
- return clientes[a];
- }
- }
- return null;
- }
- public void atualizar (Cliente cliente) throws ClienteNaoExisteException {
- if (procurar(cliente.getCPF()) != null) {
- for (int a = 0; a < this.Indice; a++) {
- if (clientes[a].getCPF().equals(cliente.getCPF())) {
- clientes[a] = cliente;
- }
- }
- } else throw new ClienteNaoExisteException(cliente);
- }
- }
- package Cliente;
- public class RepositorioClienteLista implements RepositorioCliente {
- private Cliente cliente;
- private RepositorioClienteLista prox;
- public RepositorioClienteLista () {
- this.cliente = null;
- this.prox = null;
- }
- public void inserir (Cliente cliente) throws RepositorioCheioException {
- }
- public void remover (Cliente cliente) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement