-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateId.java
More file actions
72 lines (62 loc) · 2.35 KB
/
generateId.java
File metadata and controls
72 lines (62 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
The function accept four parameter at the time of sign up by SignUpActivity and than generates a
a variable size id by trimming unnecessary 0's from input provided.
Smallest length of id = 5
Largest length of id = 7
*/
public String generateId(String mAdmissionYear, String mCollege, String mDepartment, String mRegDigit) {
String mStudentId = "";
boolean flag = false; /* Flag to check if the 0 occuring is before the non zero digit */
char[] mRegDigitArray = mRegDigit.toCharArray();
/*
switch case for the generating id depending upon the given constraints for different colleges, as system applies for
more and more colleges the switch case can be updated accordingly
*/
switch (mCollege) {
case "jc":
mStudentId = "0";
break;
case "ji":
mStudentId = "1";
break;
default:
break;
}
/*
Switch case for department inside the college as more department gets added more case can be appended
*/
switch (mDepartment) {
case "cs":
mStudentId = mStudentId + "0";
break;
case "ce":
mStudentId = mStudentId + "1";
break;
case "ee":
mStudentId = mStudentId + "2";
break;
case "ece":
mStudentId = mStudentId + "3";
break;
case "me":
mStudentId = mStudentId + "4";
break;
default:
break;
}
mStudentId = mStudentId + mAdmissionYear; /* Addition of year, example 17,18 .. */
/*
Iteration to trim unneccasry input from the given 'n' length of string, but here the length is constant a 3
*/
for (int i = 0; i < 3; i++) {
/*
If condition to determine if the occuring 0 is unnecessary or required based upon the case that if it is occuring
before any non zero character.
*/
if (!(mRegDigitArray[i] == '0'&&(!flag))) {
flag = true;
mStudentId = mStudentId + mRegDigitArray[i];
}
}
return mStudentId;
}