Skip to content

Commit f760a6a

Browse files
ChidiebereChidiebere
authored andcommitted
The Manager classes have been updated and they are almost complete
1 parent 53c2b25 commit f760a6a

12 files changed

Lines changed: 672 additions & 444 deletions

‎ModualrProject/src/database/bean/Admin.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,20 @@ public void setPassword(String password)
5151
this.password = password;
5252
}
5353

54+
/**
55+
* Returns true if the{@code Admin} object specified as an arguement can
56+
* be added to the database <br>
57+
* It checks that the {@code Admin } object is not {@code null } and
58+
* the username does not contain a space
59+
* @param admin the {@code Admin } object
60+
* @return {@code true } when the {@code Admin } is valid
61+
*/
62+
public static boolean isValid ( Admin admin ){
63+
if( admin != null && admin.getUsername() != null &&
64+
admin.getPassword() != null && !admin.getUsername().contains( " " ) )
65+
{
66+
return true;
67+
}
68+
return false;
69+
}
5470
}

‎ModualrProject/src/database/bean/Module.java‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ public void setNumberOfUnits(int numberOfUnits)
5050
this.numberOfUnits = numberOfUnits;
5151
}
5252

53-
53+
/**
54+
* Checks that a {@code Module } object by ensuring that the object is not null,
55+
* its name attribute is not {@code null} and its units is greater than 0.
56+
* Note that it does not connect to the database but ensures that the {@code Module}
57+
* object can be put perform transactions on the database
58+
*
59+
* @param module the {@code Module} object to be validated
60+
* @return true when the {@code Module } is valid
61+
*/
62+
public static boolean isValid(Module module)
63+
{
64+
if( module != null && module.getName() != null && module.getNumberOfUnits() >0)
65+
{
66+
return true;
67+
}
68+
return false;
69+
}
5470

5571
}

‎ModualrProject/src/database/bean/ModuleStatus.java‎

Lines changed: 82 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package 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
@@ -11,37 +13,59 @@
1113

1214
public 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
}

‎ModualrProject/src/database/bean/Student.java‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package database.bean;
22

3+
import java.io.File;
4+
5+
import exception.InvalidImageFormatException;
6+
37
public class Student implements Bean
48
{
59
private String idCardNumber;
610
private String firstName;
711
private String lastName;
812
private boolean active;
913
private String emailAddress;
10-
14+
private File image;
15+
1116
public Student(String id, String fName, String lName, String mail, boolean active)
1217
{
1318
setIdCardNumber(id);
@@ -75,10 +80,30 @@ public static boolean isValid( Student student ){
7580
private static boolean validateName(Student student)
7681
{
7782
if( student.getFirstName().matches( "[A-Za-z]*") &&
78-
student.getLastName().matches( "[A-Za-z]* " )){
83+
student.getLastName().matches( "[A-Za-z]*" )){
7984
return true;
8085
}
8186
return false;
8287
}
8388

89+
public File getImage()
90+
{
91+
return image;
92+
}
93+
94+
public void setImage(File image) throws InvalidImageFormatException
95+
{
96+
97+
String name = image.getName();
98+
name = name.substring(name.lastIndexOf( "."), name.length() );
99+
100+
boolean isValid = name.toLowerCase().matches( ".jpg|.png|.jpeg|.bmp");
101+
102+
if( isValid)
103+
this.image = image;
104+
else
105+
throw new InvalidImageFormatException("The student image is inalid and thus cannot be set");
106+
107+
}
108+
84109
}

0 commit comments

Comments
 (0)