11package database .bean ;
22
3- import exception .InvalidResultException ;
3+
4+
5+ import java .sql .Date ;
46
57/**
68 * Objects of this {@code ModuleStatus} represent a single row of the
1113
1214public class ModuleStatus implements Bean
1315{
16+
17+ private int id ;
1418 /**Foreign key from the Module table*/
15- private int moduleId ;
19+ private String moduleName ;
1620 /**Foreign key from the Student table*/
17- private int studentId ;
21+ private String studentId ;
1822
1923 private boolean paymentStatus ;
2024 private boolean bookingStatus ;
2125 private boolean attended ;
2226 private String result ;
2327
28+ private Date dateRegistered ;
29+
30+ public ModuleStatus (){}
31+
32+ public ModuleStatus ( int id , String moduleId , String studentId ){
33+ setId ( id );
34+ setModuleName (moduleId );
35+ setStudentId (studentId );
36+
37+ }
38+
39+ public ModuleStatus ( int id , String moduleName , String studentId , boolean paid ,
40+ boolean booked , boolean attended , String result )
41+ {
42+ this ( id , moduleName , studentId );
43+ setPaymentStatus ( paid );
44+ setBookingStatus (booked );
45+ setAttended (attended );
46+ setResult (result );
47+ }
2448 /**
2549 * Gets the moduleId of this object
2650 * @return int
2751 */
28- public int getModuleId ()
52+ public String getModuleName ()
2953 {
30- return moduleId ;
54+ return moduleName ;
3155 }
3256 /**
3357 * Sets this object's moduleId
34- * @param moduleId
58+ * @param moduleName
3559 */
36- public void setModuleId ( int moduleId )
60+ public void setModuleName ( String moduleName )
3761 {
38- this .moduleId = moduleId ;
62+ this .moduleName = moduleName ;
3963 }
4064
4165 /**
4266 *Gets this object's studentId
4367 */
44- public int getStudentId ()
68+ public String getStudentId ()
4569 {
4670 return studentId ;
4771 }
@@ -50,7 +74,7 @@ public int getStudentId()
5074 * Sets this object's studentId
5175 * @param moduleId
5276 */
53- public void setStudentId (int studentId )
77+ public void setStudentId (String studentId )
5478 {
5579 this .studentId = studentId ;
5680 }
@@ -70,6 +94,7 @@ public boolean hasPaid()
7094 */
7195 public void setPaymentStatus (boolean paymentStatus )
7296 {
97+
7398 this .paymentStatus = paymentStatus ;
7499 }
75100
@@ -83,10 +108,15 @@ public boolean hasBooked()
83108 return bookingStatus ;
84109 }
85110
86- /** Sets the booking status of this object*/
111+ /** Sets the booking status of this object. Note that
112+ * the payment statsu must be {@code true } before bookingStatus can
113+ * be true.<br>This method sets the bookingStatus to {@code false} if the
114+ * paymentStatus is {@code false }
115+ *
116+ */
87117 public void setBookingStatus (boolean bookingStatus )
88118 {
89- this .bookingStatus = bookingStatus ;
119+ this .bookingStatus = hasPaid () ? bookingStatus : false ;
90120 }
91121
92122 /**Returns true when the student( with this object's studentId )
@@ -98,14 +128,21 @@ public boolean hasAttended()
98128 {
99129 return attended ;
100130 }
131+
132+ /** Sets the attended attribute of this object. Note that
133+ * this object's booking status must be {@code true } before this {@code ModuleStatus}
134+ * attended attribute can be {@code true}
135+ * be true.<br>
136+ * The attended would be set to {@code false } if the attended bookingStatus is {@code false}
137+ *
138+ */
101139 public void setAttended (boolean attended )
102140 {
103-
104- this .attended = attended ;
141+ this .attended = hasBooked () ? attended : false ;
105142 }
106143
107144 /**
108- * Returns eitther PASS or FAIL indicatig that the course was passed or failed
145+ * Returns either PASS or FAIL indicates that the course was passed or failed
109146 *
110147 * @return String
111148 */
@@ -117,20 +154,43 @@ public String getResult()
117154
118155 /**
119156 * Sets the result of this ModuleStatus
120- * the result must be either "PASS" or "FAIL"
157+ * the result must be either "PASS" or "FAIL". <br>
158+ * Sets the result to null if the argument is invalid
121159 * @param result
122- * @throws InvalidResultException when the result is neither "pass" nor "fail"
123- */
124- public void setResult (String result ) throws InvalidResultException
160+ */
161+ public void setResult (String result )
125162 {
126163 if ( result .toLowerCase ().equals ("pass" ) ||
127164 result .toLowerCase ().equals ("fail" ) )
128165 {
129166 this .result = result ;
130167 }
131168 else
132- throw new InvalidResultException ( "The result must be either pass or fail" ) ;
169+ this . result = null ;
133170 }
134-
135-
171+ public int getId ()
172+ {
173+ return id ;
174+ }
175+ public void setId (int id )
176+ {
177+ this .id = id ;
178+ }
179+
180+ public static boolean isValid (ModuleStatus newModuleStatus )
181+ {
182+ // TODO Auto-generated method stub
183+ return false ;
184+ }
185+
186+ public Date getDateRegistered ()
187+ {
188+ return dateRegistered ;
189+ }
190+
191+ public void setDateRegistered (Date dateRegistered )
192+ {
193+ this .dateRegistered = dateRegistered ;
194+ }
195+
136196}
0 commit comments