| 1 | /* |
| 2 | * To change this template, choose Tools | Templates |
| 3 | * and open the template in the editor. |
| 4 | */ |
| 5 | package cviceni_12; |
| 6 | |
| 7 | /** |
| 8 | * |
| 9 | * @author hapallen |
| 10 | */ |
| 11 | public class Zakaznik { |
| 12 | |
| 13 | private String jmeno; |
| 14 | private String prijmeni; |
| 15 | private int vek; |
| 16 | |
| 17 | public Zakaznik(String jmeno, String prijmeni, int vek) { |
| 18 | this.jmeno = jmeno; |
| 19 | this.prijmeni = prijmeni; |
| 20 | this.vek = vek; |
| 21 | } |
| 22 | |
| 23 | public String getJmeno() { |
| 24 | return jmeno; |
| 25 | } |
| 26 | |
| 27 | public void setJmeno(String jmeno) { |
| 28 | this.jmeno = jmeno; |
| 29 | } |
| 30 | |
| 31 | public String getPrijmeni() { |
| 32 | return prijmeni; |
| 33 | } |
| 34 | |
| 35 | public void setPrijmeni(String prijmeni) { |
| 36 | this.prijmeni = prijmeni; |
| 37 | } |
| 38 | |
| 39 | public int getVek() { |
| 40 | return vek; |
| 41 | } |
| 42 | |
| 43 | public void setVek(int vek) throws Exception { |
| 44 | if (vek >= 0) { |
| 45 | this.vek = vek; |
| 46 | } else { |
| 47 | throw new Exception("Nespraavny vek"); |
| 48 | } |
| 49 | |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public boolean equals(Object obj) { |
| 54 | if (obj instanceof Zakaznik) { |
| 55 | Zakaznik z = (Zakaznik) obj; |
| 56 | if (this.prijmeni.equalsIgnoreCase(z.getPrijmeni()) |
| 57 | && this.jmeno.equalsIgnoreCase(z.getJmeno()) |
| 58 | && this.vek == z.getVek()) { |
| 59 | return true; |
| 60 | } |
| 61 | } |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public String toString() { |
| 67 | return String.format("Zakaznik: prijmeni: %s,jmeno: %s, vek: %d;", this.getPrijmeni(), this.getJmeno(), this.getVek()); |
| 68 | } |
| 69 | } |