×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: anti laila
Added: May 26, 2022 5:54 PM
Views: 10
  1. package com.example.sqlitedemo03.model;
  2.  
  3. import java.io.Serializable;
  4. import java.util.Objects;
  5.  
  6. public class Friend implements Serializable {
  7.     private int id;
  8.     private final String name;
  9.     private final String address;
  10.     private final String phone;
  11.  
  12.     public Friend(int id, String name, String address, String phone) {
  13.         this.id = id;
  14.         this.name = name;
  15.         this.address = address;
  16.         this.phone = phone;
  17.     }
  18.  
  19.     public Friend(String name, String address, String phone) {
  20.         this.name = name;
  21.         this.address = address;
  22.         this.phone = phone;
  23.     }
  24.  
  25.     public int getId() {
  26.         return id;
  27.     }
  28.  
  29.     public String getName() {
  30.         return name;
  31.     }
  32.  
  33.     public String getAddress() {
  34.         return address;
  35.     }
  36.  
  37.     public String getPhone() {
  38.         return phone;
  39.     }
  40.  
  41.     @Override
  42.     public boolean equals(Object o) {
  43.         if (this == o) return true;
  44.         if (o == null || getClass() != o.getClass()) return false;
  45.         Friend friend = (Friend) o;
  46.         return id == friend.id && name.equals(friend.name) && Objects.equals(address, friend.address) && Objects.equals(phone, friend.phone);
  47.     }
  48.  
  49.     @Override
  50.     public int hashCode() {
  51.         return Objects.hash(id, name, address, phone);
  52.     }
  53.  
  54.     @Override
  55.     public String toString() {
  56.         return String.format("%-3d %-20s %-30s %-14", getId(), getName(), getAddress(), getPhone());
  57.     }
  58. }
  59.