Advertisement
vinidj

Rep Clientes e exceções

Jun 13th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. package Cliente;
  2.  
  3. public interface RepositorioCliente {
  4. void inserir (Cliente cliente) throws RepositorioCheioException;
  5. void remorer (Cliente cliente) throws ClienteNaoExisteException;
  6. Cliente procurar (String cpf);
  7. void atualizar (Cliente cliente) throws ClienteNaoExisteException;
  8. }
  9.  
  10. package Cliente;
  11.  
  12. public class RepositorioCheioException extends Exception {
  13. private Cliente cliente;
  14. public RepositorioCheioException (Cliente cliente) {
  15. super ("O cliente" + cliente.getCPF() +"não pois o limite de cadastros foi atingido.");
  16. this.cliente = cliente;
  17. }
  18. }
  19.  
  20. package Cliente;
  21.  
  22. public class ClienteNaoExisteException extends Exception {
  23. private Cliente cliente;
  24. public ClienteNaoExisteException (Cliente cliente) {
  25. super("O cliente" + cliente.getCPF() + "não existe");
  26. this.cliente = cliente;
  27. }
  28. }
  29.  
  30. package Cliente;
  31.  
  32. public class RepositorioClienteArray implements RepositorioCliente {
  33. private Cliente[] clientes;
  34. private int Indice;
  35. public RepositorioClienteArray (int tam) {
  36. clientes = new Cliente[tam];
  37. this.Indice = 0;
  38. }
  39. public void inserir (Cliente cliente) throws RepositorioCheioException {
  40. if (this.Indice != clientes.length) {
  41. clientes[this.Indice] = cliente;
  42. this.Indice++;
  43. } else throw new RepositorioCheioException(cliente);
  44. }
  45. public void remorer (Cliente cliente) throws ClienteNaoExisteException {
  46. if (procurar(cliente.getCPF()) != null) {
  47. boolean removeu = false;
  48. for (int b = 0; b < this.Indice; b++) {
  49. if (clientes[b].getCPF().equals(cliente.getCPF())) {
  50. clientes[b] = null;
  51. removeu = true;
  52. }
  53. if (removeu) {
  54. if (b < this.Indice - 1) {
  55. clientes[b] = clientes[b + 1];
  56. }
  57. }
  58. }
  59. this.Indice--;
  60. } else throw new ClienteNaoExisteException(cliente);
  61. }
  62. public Cliente procurar (String cpf) {
  63. for (int a = 0; a < this.Indice; a++) {
  64. if (clientes[a].getCPF().equals(cpf)) {
  65. return clientes[a];
  66. }
  67. }
  68. return null;
  69. }
  70. public void atualizar (Cliente cliente) throws ClienteNaoExisteException {
  71. if (procurar(cliente.getCPF()) != null) {
  72. for (int a = 0; a < this.Indice; a++) {
  73. if (clientes[a].getCPF().equals(cliente.getCPF())) {
  74. clientes[a] = cliente;
  75. }
  76. }
  77. } else throw new ClienteNaoExisteException(cliente);
  78. }
  79. }
  80.  
  81. package Cliente;
  82.  
  83. public class RepositorioClienteLista implements RepositorioCliente {
  84. private Cliente cliente;
  85. private RepositorioClienteLista prox;
  86. public RepositorioClienteLista () {
  87. this.cliente = null;
  88. this.prox = null;
  89. }
  90. public void inserir (Cliente cliente) throws RepositorioCheioException {
  91.  
  92. }
  93. public void remover (Cliente cliente) {
  94.  
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement