YerkebulanOrda111

IIN

Nov 9th, 2025
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. import java.util.Objects;
  2.  
  3. import java.time.LocalDate;
  4.  
  5. public class Human {
  6.     String name;
  7.     String surName;
  8.     int age;
  9.     LocalDate dateOfBirth;
  10.     int iin;
  11.  
  12.     public Human(String name, String surName, int age, LocalDate dateOfBirth, int iin) {
  13.         this.name = name;
  14.         this.surName = surName;
  15.         this.age = age;
  16.         this.dateOfBirth = dateOfBirth;
  17.         this.iin = iin;
  18.     }
  19.     @Override
  20.     public boolean equals(Object o) {
  21.         if (this == o) return true;
  22.         if (o == null || getClass() != o.getClass()) return false;
  23.         Human human = (Human) o;
  24.         return iin == human.iin;
  25. }
  26.  
  27.     @Override
  28.     public int hashCode() {
  29.         return Objects.hash(iin); // хэш тоже строим по IIN
  30.     }
  31. }
  32.  
  33. public class Main {
  34.     public static void main(String[] args) {
  35.       Human h1 = new Human("Yerkebulan", "Orda", 30, LocalDate.of(1995, 5, 5), 123456789);
  36.         Human h2 = new Human("Yerkebulan", "Orda", 30, LocalDate.of(1995, 5, 5), 123456789);
  37.         Human h3 = new Human("Almas", "Omarov", 22, LocalDate.of(2003, 3, 3), 987654321);
  38.  
  39.         System.out.println("h1.equals(h2): " + h1.equals(h2));
  40.         System.out.println("h1.equals(h3): " + h1.equals(h3));
  41.        
  42.             }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment