Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.81 KB | None | 0 0
  1. import java.util.Objects;
  2.  
  3. import org.svetovid.io.SvetovidReader;
  4.  
  5. public class Automobil extends InfoTip {
  6.  
  7.     private String model;
  8.     private Boja bojaKaroserije, bojaSedista, bojaVolana;
  9.  
  10.     public Automobil() {
  11.     }
  12.    
  13.     public Automobil(String m, Boja b1, Boja b2, Boja b3) {
  14.         model = m;
  15.         bojaKaroserije = b1;
  16.         bojaSedista = b2;
  17.         bojaVolana = b3;
  18.     }
  19.    
  20.     @Override
  21.     public Automobil ucitaj(SvetovidReader read) {
  22.         // prvo citamo model u jednom redu
  23.         String model = read.readLine();
  24.        
  25.         // posto metod `ucitaj` nije staticki treba nam
  26.         // pomocni objekat za ucitavanje
  27.         Boja temp = new Boja();
  28.        
  29.         Boja b1 = temp.ucitaj(read);
  30.         Boja b2 = temp.ucitaj(read);
  31.         Boja b3 = temp.ucitaj(read);
  32.        
  33.         // postoje prazni redovi medju podacima
  34.         read.readLine();
  35.        
  36.         return new Automobil(model, b1, b2, b3);
  37.     }
  38.    
  39.     @Override
  40.     public boolean equals(Object o) {
  41.         if (this == o)
  42.             return true;
  43.        
  44.         if (o == null)
  45.             return false;
  46.        
  47.         if (this.getClass() != o.getClass())
  48.             return false;
  49.        
  50.         Automobil a = (Automobil) o;
  51.        
  52.         if (!Objects.equals(model, a.model))
  53.             return false;
  54.        
  55.         if (!Objects.equals(bojaKaroserije, a.bojaKaroserije))
  56.             return false;
  57.  
  58.         if (!Objects.equals(bojaSedista, a.bojaSedista))
  59.             return false;
  60.        
  61.         if (!Objects.equals(bojaVolana, a.bojaVolana))
  62.             return false;
  63.        
  64.         return true;
  65.     }
  66.    
  67.     public int hashCode() {
  68.         int rez = 0;
  69.         if (model != null)
  70.             rez += model.hashCode();
  71.         if (bojaSedista != null)
  72.             rez += 997 * bojaSedista.hashCode();
  73.         if (bojaKaroserije != null)
  74.             rez += 13  * bojaKaroserije.hashCode();
  75.         if (bojaVolana != null)
  76.             rez += bojaVolana.hashCode();
  77.         return rez;
  78.     }
  79.    
  80.     // pomocni metod za lakse testiranje
  81.     public static void main(String[] args) {
  82.         new TestHash(new Automobil(), "automobili/", "a").run();
  83.     }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement