001package edu.pdx.cs.joy.jdbc;
002
003/**
004 * Represents a department in a college course catalog.
005 * Each department has a unique ID and a name.
006 */
007public class Department {
008  private int id;
009  private String name;
010
011  /**
012   * Creates a new Department with the specified ID and name.
013   *
014   * @param id the unique identifier for the department
015   * @param name the name of the department
016   */
017  public Department(int id, String name) {
018    this.id = id;
019    this.name = name;
020  }
021
022  /**
023   * Creates a new Department with the specified name.
024   * The ID will be auto-generated when the department is saved to the database.
025   *
026   * @param name the name of the department
027   */
028  public Department(String name) {
029    this.name = name;
030  }
031
032  /**
033   * Creates a new Department with no initial values.
034   * Useful for frameworks that use reflection.
035   */
036  public Department() {
037  }
038
039  /**
040   * Returns the ID of this department.
041   *
042   * @return the department ID
043   */
044  public int getId() {
045    return id;
046  }
047
048  /**
049   * Sets the ID of this department.
050   *
051   * @param id the department ID
052   */
053  public void setId(int id) {
054    this.id = id;
055  }
056
057  /**
058   * Returns the name of this department.
059   *
060   * @return the department name
061   */
062  public String getName() {
063    return name;
064  }
065
066  /**
067   * Sets the name of this department.
068   *
069   * @param name the department name
070   */
071  public void setName(String name) {
072    this.name = name;
073  }
074
075  @Override
076  public String toString() {
077    return "Department{" +
078      "id=" + id +
079      ", name='" + name + '\'' +
080      '}';
081  }
082
083  @Override
084  public boolean equals(Object o) {
085    if (this == o) return true;
086    if (o == null || getClass() != o.getClass()) return false;
087
088    Department that = (Department) o;
089
090    if (id != that.id) return false;
091    return name != null ? name.equals(that.name) : that.name == null;
092  }
093
094  @Override
095  public int hashCode() {
096    int result = id;
097    result = 31 * result + (name != null ? name.hashCode() : 0);
098    return result;
099  }
100}
101