001package edu.pdx.cs.joy.jdbc; 002 003/** 004 * Represents a course in a college course catalog. 005 * Each course has a unique ID, a title, is associated with a department, and has a number of credits. 006 */ 007public class Course { 008 private int id; 009 private String title; 010 private int departmentId; 011 private int credits; 012 013 /** 014 * Creates a new Course with the specified title, department ID, and credits. 015 * 016 * @param title the title of the course 017 * @param departmentId the numeric ID of the department offering this course 018 * @param credits the number of credits for this course 019 */ 020 public Course(String title, int departmentId, int credits) { 021 this.title = title; 022 this.departmentId = departmentId; 023 this.credits = credits; 024 } 025 026 /** 027 * Creates a new Course with no initial values. 028 * Useful for frameworks that use reflection. 029 */ 030 public Course() { 031 } 032 033 /** 034 * Returns the unique ID of this course. 035 * 036 * @return the course ID 037 */ 038 public int getId() { 039 return id; 040 } 041 042 /** 043 * Sets the unique ID of this course. 044 * 045 * @param id the course ID 046 */ 047 public void setId(int id) { 048 this.id = id; 049 } 050 051 /** 052 * Returns the title of this course. 053 * 054 * @return the course title 055 */ 056 public String getTitle() { 057 return title; 058 } 059 060 /** 061 * Sets the title of this course. 062 * 063 * @param title the course title 064 */ 065 public void setTitle(String title) { 066 this.title = title; 067 } 068 069 /** 070 * Returns the department ID for this course. 071 * 072 * @return the department ID 073 */ 074 public int getDepartmentId() { 075 return departmentId; 076 } 077 078 /** 079 * Sets the department ID for this course. 080 * 081 * @param departmentId the department ID 082 */ 083 public void setDepartmentId(int departmentId) { 084 this.departmentId = departmentId; 085 } 086 087 /** 088 * Returns the number of credits for this course. 089 * 090 * @return the number of credits 091 */ 092 public int getCredits() { 093 return credits; 094 } 095 096 /** 097 * Sets the number of credits for this course. 098 * 099 * @param credits the number of credits 100 */ 101 public void setCredits(int credits) { 102 this.credits = credits; 103 } 104 105 @Override 106 public String toString() { 107 return "Course{" + 108 "id=" + id + 109 ", title='" + title + '\'' + 110 ", departmentId=" + departmentId + 111 ", credits=" + credits + 112 '}'; 113 } 114 115 @Override 116 public boolean equals(Object o) { 117 if (this == o) return true; 118 if (o == null || getClass() != o.getClass()) return false; 119 120 Course course = (Course) o; 121 122 if (id != course.id) return false; 123 if (departmentId != course.departmentId) return false; 124 if (credits != course.credits) return false; 125 return title != null ? title.equals(course.title) : course.title == null; 126 } 127 128 @Override 129 public int hashCode() { 130 int result = id; 131 result = 31 * result + (title != null ? title.hashCode() : 0); 132 result = 31 * result + departmentId; 133 result = 31 * result + credits; 134 return result; 135 } 136}