Advertisement
Mitoeap

Untitled

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