Advertisement
jtentor

TP1 - Caso Ejemplo d) - Libro.Java

Sep 3rd, 2020
1,658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.77 KB | None | 0 0
  1. // Created by Julio Tentor <jtentor@fi.unju.edu.ar>
  2. //
  3.  
  4.  
  5. import java.util.Objects;
  6.  
  7. public class Libro {
  8.  
  9.     //region Attributes
  10.     private String titulo;
  11.     private String autor;
  12.     private String editorial;
  13.     private Integer anioPublicacion;
  14.     private Double precio;
  15.     //endregion
  16.  
  17.     //region Getters and Setters
  18.     public String getTitulo() {
  19.         return this.titulo;
  20.     }
  21.     public String setTitulo(String titulo) {
  22.         this.titulo = titulo;
  23.         return this.titulo;
  24.     }
  25.  
  26.     public String getAutor() {
  27.         return this.autor;
  28.     }
  29.     public String setAutor(String autor) {
  30.         this.autor = autor;
  31.         return this.autor;
  32.     }
  33.  
  34.     public String getEditorial() {
  35.         return this.editorial;
  36.     }
  37.     public String setEditorial(String editorial) {
  38.         this.editorial = editorial;
  39.         return this.editorial;
  40.     }
  41.  
  42.     public Integer getAnioPublicacion() {
  43.         return this.anioPublicacion;
  44.     }
  45.     public Integer setAnioPublicacion (Integer anioPublicacion) {
  46.         this.anioPublicacion = anioPublicacion;
  47.         return this.anioPublicacion;
  48.     }
  49.  
  50.     public Double getPrecio() {
  51.         return this.precio;
  52.     }
  53.     public Double setPrecio(Double precio) {
  54.         this.precio = precio;
  55.         return this.precio;
  56.     }
  57.     //endregion
  58.  
  59.     //region Constructors
  60.     public Libro() {
  61.         this("sin título", "sin autor", "sin editorial", 0,0.0);
  62.     }
  63.     public Libro(String titulo, String autor) {
  64.         this(titulo, autor, "sin editorial", 0,0.0);
  65.     }
  66.     public Libro(String titulo, String autor, Integer anioPublicacion) {
  67.         this(titulo, autor, "sin editorial", anioPublicacion,0.0);
  68.     }
  69.     public Libro(String titulo, String autor, Integer anioPublicacion, Double precio) {
  70.         this(titulo, autor, "sin editorial", anioPublicacion, precio);
  71.     }
  72.     public Libro(String titulo, String autor, Double precio) {
  73.         this(titulo, autor, "sin editorial", 0, precio);
  74.     }
  75.     public Libro(String titulo, String autor, String editorial) {
  76.         this(titulo, autor, editorial, 0,0.0);
  77.     }
  78.     public Libro(String titulo, String autor, String editorial, Integer anioPublicacion) {
  79.         this(titulo, autor, editorial, anioPublicacion,0.0);
  80.     }
  81.     public Libro(String titulo, String autor, String editorial, Double precio) {
  82.         this(titulo, autor, editorial, 0, precio);
  83.     }
  84.     public Libro(String titulo, String autor, String editorial, Integer anioPublicacion, Double precio) {
  85.         setTitulo(titulo); // doble encapsulamiento
  86.         setAutor(autor);
  87.         setEditorial(editorial);
  88.         setAnioPublicacion(anioPublicacion);
  89.         setPrecio(precio);
  90.     }
  91.     //endregion
  92.  
  93.     //region Override Object basic methods
  94.     @Override
  95.     public boolean equals(Object o) {
  96.         if (this == o) return true;
  97.         if (o == null || getClass() != o.getClass()) return false;
  98.         Libro libro = (Libro) o;
  99.         return Objects.equals(getTitulo(), libro.getTitulo()) &&
  100.                 Objects.equals(getAutor(), libro.getAutor()) &&
  101.                 Objects.equals(getEditorial(), libro.getEditorial()) &&
  102.                 Objects.equals(getAnioPublicacion(), libro.getAnioPublicacion());
  103.     }
  104.  
  105.     @Override
  106.     public int hashCode() {
  107.         return Objects.hash(getTitulo(), getAutor(), getEditorial(), getAnioPublicacion());
  108.     }
  109.  
  110.     @Override
  111.     public String toString() {
  112.         return "Libro " +
  113.                 "Título='" + getTitulo() + '\'' +
  114.                 ", Autor='" + getAutor() + '\'' +
  115.                 ", Editorial='" + getEditorial() + '\'' +
  116.                 ", Año de Publicación=" + getAnioPublicacion() +
  117.                 ", Precio=" + getPrecio() +
  118.                 '\n';
  119.     }
  120.     //endregion
  121. }
  122.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement