Roke98

Clase Videos

Oct 30th, 2022 (edited)
977
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.22 KB | None | 0 0
  1. import java.lang.Comparable;
  2. import java.text.DecimalFormat;
  3. import java.util.Objects;
  4.  
  5. @SuppressWarnings("rawtypes")
  6. public class Videos implements Comparable{
  7.     DecimalFormat df = new DecimalFormat("#.00");
  8.     private String id;
  9.     private String titulo;
  10.     private String creador;
  11.     private float duracion;
  12.    
  13.     public Videos() {
  14.        
  15.     }
  16.    
  17.     public Videos  (String id, String titulo, String creador , float duracion){
  18.        
  19.         this.id = id;
  20.         this.titulo = titulo;
  21.         this.creador = creador;
  22.         this.duracion = duracion;
  23.     }
  24.    
  25.    
  26.     @Override
  27.     public String toString() {
  28.         return "Video [id=" + id + ", titulo=" + titulo + ", creador=" + creador + ", duracion=" + df.format(getDuracion()) + "]"+"\n";
  29.     }
  30.    
  31.  
  32.     public String getId() {
  33.         return id;
  34.     }
  35.  
  36.     public void setId(String id) {
  37.         this.id = id;
  38.     }
  39.  
  40.     public String getTitulo() {
  41.         return titulo;
  42.     }
  43.  
  44.     public void setTitulo(String titulo) {
  45.         this.titulo = titulo;
  46.     }
  47.  
  48.     public String getCreador() {
  49.         return creador;
  50.     }
  51.  
  52.     public void setCreador(String creador) {
  53.         this.creador = creador;
  54.     }
  55.  
  56.     public float getDuracion() {
  57.         return duracion;
  58.     }
  59.  
  60.     public void setDuracion(float duracion) {
  61.         this.duracion = duracion;
  62.     }
  63.    
  64.     public boolean equals(Object obj) {
  65.         if (this==obj)return true;
  66.         if (obj==null)return false;
  67.         if (getClass() != obj.getClass())return false;
  68.         final Videos otro = (Videos) obj;
  69.         if (!Objects.equals(this.id, otro.getId()))return false;
  70.        
  71.         return true;
  72.     }
  73.    
  74.     public int compareTo(Object o) {
  75.         Videos vid = (Videos) o;
  76.        
  77.         if(this.duracion<vid.getDuracion()) return -1;
  78.         if(this.duracion>vid.getDuracion()) return 1;
  79.        
  80.         return 0;
  81.     }
  82.    
  83.     public int compareTitulo(Object o) {
  84.         Videos vid = (Videos) o;
  85.         int titulo1 = 0,titulo2 = 0;
  86.         for(char c: this.titulo.toCharArray()) {
  87.             titulo1 += c;
  88.         }
  89.         for(char c: vid.titulo.toCharArray()) {
  90.             titulo2 += c;
  91.         }
  92.        
  93.         if(titulo1<titulo2) return -1;
  94.         if(titulo1>titulo2) return 1;
  95.        
  96.         return 0;
  97.     }
  98.    
  99. }
Advertisement
Add Comment
Please, Sign In to add comment