Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. public class FacturaEmitida extends Factura {
  2.  
  3. private String emisor;
  4. private String cliente;
  5.  
  6. FacturaEmitida(String cif, int numFactura, double total, String emisor, String cliente){
  7.  
  8. super(cif,numFactura,total);
  9. this.emisor = emisor;
  10. this.cliente = cliente;
  11. }
  12.  
  13. public void imprimirFactura() {
  14.  
  15. System.out.println("CIF: " + this.getCif() + "n" +
  16. "Número de factura: " + this.getNumFactura() + "n" +
  17. "Emisor: " + this.getEmisor() + "n" +
  18. "Cliente: " + this.getCliente() + "n" +
  19. "Total: " + this.getTotal() + "n");
  20. }
  21.  
  22. public class ValorNoValido extends Exception{
  23. public ValorNoValido(){ }
  24. public ValorNoValido(String cadena){
  25. super(cadena); //Llama al constructor de Exception y le pasa el contenido de cadena
  26. }
  27. }
  28.  
  29. public void comprobarImporte() throws ValorNoValido {
  30.  
  31. if(this.getTotal() < 0){
  32. throw new ValorNoValido("El importe total no puede ser negativo.");
  33. }
  34. }
  35.  
  36. public String comprobarEmisor(String emisor){
  37. //name.trim().length() == 0
  38. if (this.getEmisor() == "" || this.getEmisor() == null) {
  39. this.emisor = "";
  40. throw new RuntimeException("El campo de Emisor no puede quedar vacío.");
  41. }
  42. return emisor;
  43.  
  44. }
  45.  
  46. /**
  47. * @return the emisor
  48. */
  49. public String getEmisor() {
  50. return emisor;
  51. }
  52.  
  53. /**
  54. * @param emisor the emisor to set
  55. */
  56. public void setEmisor(String emisor) {
  57. this.emisor = emisor;
  58. }
  59.  
  60. /**
  61. * @return the cliente
  62. */
  63. public String getCliente() {
  64. return cliente;
  65. }
  66.  
  67. /**
  68. * @param cliente the cliente to set
  69. */
  70. public void setCliente(String cliente) {
  71. this.cliente = cliente;
  72. }
  73.  
  74. }
  75.  
  76. public class Factura {
  77.  
  78. private String cif;
  79. private int numFactura;
  80. private double total;
  81.  
  82. Factura(String cif, int numFactura, double total){
  83. this.cif = cif;
  84. this.numFactura = numFactura;
  85. this.total = total;
  86. }
  87.  
  88. /**
  89. * @return the cif
  90. */
  91. public String getCif() {
  92. return cif;
  93. }
  94.  
  95. /**
  96. * @param cif the cif to set
  97. */
  98. public void setCif(String cif) {
  99. this.cif = cif;
  100. }
  101.  
  102. /**
  103. * @return the numFactura
  104. */
  105. public int getNumFactura() {
  106. return numFactura;
  107. }
  108.  
  109. /**
  110. * @param numFactura the numFactura to set
  111. */
  112. public void setNumFactura(int numFactura) {
  113. this.numFactura = numFactura;
  114. }
  115.  
  116. /**
  117. * @return the total
  118. */
  119. public double getTotal() {
  120. return total;
  121. }
  122.  
  123. /**
  124. * @param total the total to set
  125. */
  126. public void setTotal(double total) {
  127. this.total = total;
  128. }
  129.  
  130. }
  131.  
  132. public class Main {
  133.  
  134. public static void main(String[] args) {
  135. FacturaEmitida fact = new FacturaEmitida("844571X", 222, 1500, "", "Weist Cheing");
  136. try {
  137. fact.comprobarImporte();
  138. fact.comprobarEmisor(fact.getEmisor());
  139. fact.imprimirFactura();
  140. }catch (FacturaEmitida.ValorNoValido e) {
  141. System.out.println(e.getMessage());
  142. }catch(RuntimeException ex){
  143. System.out.println(ex);
  144. }
  145. }
  146.  
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement