001package edu.pdx.cs.joy.jdbc; 002 003import java.time.LocalDate; 004 005/** 006 * Represents an academic term (such as Fall 2024 or Spring 2025) during which courses are offered. 007 * Each term has a unique ID, a name, and start and end dates. 008 */ 009public class AcademicTerm { 010 private int id; 011 private String name; 012 private LocalDate startDate; 013 private LocalDate endDate; 014 015 /** 016 * Creates a new AcademicTerm with the specified name, start date, and end date. 017 * 018 * @param name the name of the term (e.g., "Fall 2024") 019 * @param startDate the start date of the term 020 * @param endDate the end date of the term 021 */ 022 public AcademicTerm(String name, LocalDate startDate, LocalDate endDate) { 023 this.name = name; 024 this.startDate = startDate; 025 this.endDate = endDate; 026 } 027 028 /** 029 * Creates a new AcademicTerm with the specified ID, name, start date, and end date. 030 * 031 * @param id the unique identifier for the term 032 * @param name the name of the term (e.g., "Fall 2024") 033 * @param startDate the start date of the term 034 * @param endDate the end date of the term 035 */ 036 public AcademicTerm(int id, String name, LocalDate startDate, LocalDate endDate) { 037 this.id = id; 038 this.name = name; 039 this.startDate = startDate; 040 this.endDate = endDate; 041 } 042 043 /** 044 * Creates a new AcademicTerm with no initial values. 045 * Useful for frameworks that use reflection. 046 */ 047 public AcademicTerm() { 048 } 049 050 /** 051 * Returns the unique ID of this academic term. 052 * 053 * @return the term ID 054 */ 055 public int getId() { 056 return id; 057 } 058 059 /** 060 * Sets the unique ID of this academic term. 061 * 062 * @param id the term ID 063 */ 064 public void setId(int id) { 065 this.id = id; 066 } 067 068 /** 069 * Returns the name of this academic term. 070 * 071 * @return the term name 072 */ 073 public String getName() { 074 return name; 075 } 076 077 /** 078 * Sets the name of this academic term. 079 * 080 * @param name the term name 081 */ 082 public void setName(String name) { 083 this.name = name; 084 } 085 086 /** 087 * Returns the start date of this academic term. 088 * 089 * @return the start date 090 */ 091 public LocalDate getStartDate() { 092 return startDate; 093 } 094 095 /** 096 * Sets the start date of this academic term. 097 * 098 * @param startDate the start date 099 */ 100 public void setStartDate(LocalDate startDate) { 101 this.startDate = startDate; 102 } 103 104 /** 105 * Returns the end date of this academic term. 106 * 107 * @return the end date 108 */ 109 public LocalDate getEndDate() { 110 return endDate; 111 } 112 113 /** 114 * Sets the end date of this academic term. 115 * 116 * @param endDate the end date 117 */ 118 public void setEndDate(LocalDate endDate) { 119 this.endDate = endDate; 120 } 121 122 @Override 123 public String toString() { 124 return "AcademicTerm{" + 125 "id=" + id + 126 ", name='" + name + '\'' + 127 ", startDate=" + startDate + 128 ", endDate=" + endDate + 129 '}'; 130 } 131 132 @Override 133 public boolean equals(Object o) { 134 if (this == o) return true; 135 if (o == null || getClass() != o.getClass()) return false; 136 137 AcademicTerm that = (AcademicTerm) o; 138 139 if (id != that.id) return false; 140 if (name != null ? !name.equals(that.name) : that.name != null) return false; 141 if (startDate != null ? !startDate.equals(that.startDate) : that.startDate != null) return false; 142 return endDate != null ? endDate.equals(that.endDate) : that.endDate == null; 143 } 144 145 @Override 146 public int hashCode() { 147 int result = id; 148 result = 31 * result + (name != null ? name.hashCode() : 0); 149 result = 31 * result + (startDate != null ? startDate.hashCode() : 0); 150 result = 31 * result + (endDate != null ? endDate.hashCode() : 0); 151 return result; 152 } 153} 154