Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Objects;
- import org.svetovid.io.SvetovidReader;
- public class Automobil extends InfoTip {
- private String model;
- private Boja bojaKaroserije, bojaSedista, bojaVolana;
- public Automobil() {
- }
- public Automobil(String m, Boja b1, Boja b2, Boja b3) {
- model = m;
- bojaKaroserije = b1;
- bojaSedista = b2;
- bojaVolana = b3;
- }
- @Override
- public Automobil ucitaj(SvetovidReader read) {
- // prvo citamo model u jednom redu
- String model = read.readLine();
- // posto metod `ucitaj` nije staticki treba nam
- // pomocni objekat za ucitavanje
- Boja temp = new Boja();
- Boja b1 = temp.ucitaj(read);
- Boja b2 = temp.ucitaj(read);
- Boja b3 = temp.ucitaj(read);
- // postoje prazni redovi medju podacima
- read.readLine();
- return new Automobil(model, b1, b2, b3);
- }
- @Override
- public boolean equals(Object o) {
- if (this == o)
- return true;
- if (o == null)
- return false;
- if (this.getClass() != o.getClass())
- return false;
- Automobil a = (Automobil) o;
- if (!Objects.equals(model, a.model))
- return false;
- if (!Objects.equals(bojaKaroserije, a.bojaKaroserije))
- return false;
- if (!Objects.equals(bojaSedista, a.bojaSedista))
- return false;
- if (!Objects.equals(bojaVolana, a.bojaVolana))
- return false;
- return true;
- }
- public int hashCode() {
- int rez = 0;
- if (model != null)
- rez += model.hashCode();
- if (bojaSedista != null)
- rez += 997 * bojaSedista.hashCode();
- if (bojaKaroserije != null)
- rez += 13 * bojaKaroserije.hashCode();
- if (bojaVolana != null)
- rez += bojaVolana.hashCode();
- return rez;
- }
- // pomocni metod za lakse testiranje
- public static void main(String[] args) {
- new TestHash(new Automobil(), "automobili/", "a").run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement