LeonardCHoo

javasample

Nov 30th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. public class Customer {
  2.    private String name;
  3.    private String email;
  4.    private String company;
  5.  
  6.    public Customer(String name) {
  7.        this(name, "", "");
  8.    }
  9.  
  10.    public Customer(String name, String email) {
  11.        this(name, email, "");
  12.    }
  13.  
  14.    public Customer(String name, String email, String company) {
  15.        this.name = name;
  16.        this.email = email;
  17.        this.company = company;
  18.    }
  19.  
  20.    public String getName() {
  21.        return name;
  22.    }
  23.  
  24.    public void setName(String name) {
  25.        this.name = name;
  26.    }
  27.  
  28.    public String getEmail() {
  29.        return email;
  30.    }
  31.  
  32.    public void setEmail(String email) {
  33.        this.email = email;
  34.    }
  35.  
  36.    public String getCompany() {
  37.        return company;
  38.    }
  39.  
  40.    public void setCompany(String company) {
  41.        this.company = company;
  42.    }
  43.  
  44.    @Override
  45.    public boolean equals(Object o) {
  46.        if (this == o) return true;
  47.        if (o == null || getClass() != o.getClass()) return false;
  48.  
  49.        Customer customer = (Customer) o;
  50.  
  51.        if (name != null ? !name.equals(customer.name) : customer.name != null) return false;
  52.        if (email != null ? !email.equals(customer.email) : customer.email != null) return false;
  53.        return company != null ? company.equals(customer.company) : customer.company == null;
  54.    }
  55.  
  56.    @Override
  57.    public int hashCode() {
  58.        int result = name != null ? name.hashCode() : 0;
  59.        result = 31 * result + (email != null ? email.hashCode() : 0);
  60.        result = 31 * result + (company != null ? company.hashCode() : 0);
  61.        return result;
  62.    }
  63.  
  64.    @Override
  65.    public String toString() {
  66.        return "Customer{" +
  67.                "name='" + name + '\'' +
  68.                ", email='" + email + '\'' +
  69.                ", company='" + company + '\'' +
  70.                '}';
  71.    }
  72. }
  73.  
  74. /*
  75. Kotlin alternative
  76.  
  77. data class Customer(var name: String, var email: String = "",
  78.                     var company: String = "")
  79.  
  80. */
Add Comment
Please, Sign In to add comment