Sei sulla pagina 1di 7

Case Study # 2: Student Record System Implementation

using Linked List


Note: All those in red font are actual error/success messages that needs to
appear on the output.
Submission Date: February 21, 2015
General Instruction:
1. Strictly no use of classes JOptionPane, Scanner and other input-related pre-defined
classes in Java. Programmer must implement Command-Line Arguments as means of
getting input from the user.
2. Strictly no use of arrays (except for the Command-Line Arguments itself).
3. Strictly no use of pre-defined LinkedList class from package java.util and its
implementations. Programmer must use the existing codes as discussed during
lecture and provide manual codes for insertAtMiddle or removeAtMiddle.
4. The linked list for this case study can only hold a maximum of 5 students.

Commands:
A,a = Add a student record
E,e = Edit a student record
D,d = Delete a student record
9)
S,s = Sort a student record
P,p = Print a student record

Fields:
Student #: Programmer to generate 1 to 5, uniquely.
Name: Alphabetic Characters (A-Z, a-z)
Address: Alphanumeric Characters (A-Z, a-z, 0Age: 16 to 25 only, inclusive
Gender: M, m, F, f

General Format:
java <filename without extension> A <Name> <Address> <Age> <Gender> E <Student
#> <Modifier: can be Name, Address, Age, Gender> <new value> D <Student #> S
<Modifier: can be ASC, DESC> <Modifier: can be Number, Name, Address, Age> P

Validations:
In general, there will be two (2) types of validation:
1. Type 1 Validation if any of these errors occurred, immediately EXIT FROM THE
PROGRAM.
2. Type 2 Validation if any of these errors occurred, DO NOT EXIT from the program.
Instead, move and read/execute the next command.

Type 1 Validation:
-

Note that if ANY of these errors occurred, immediate EXIT FROM THE PROGRAM.

1. The first argument (args[0]) must ALWAYS be equal to any of the following: (A, a,
E, e, D, d, S, s ,P, p), otherwise, EXIT FROM THE PROGRAM.
2. The last argument must ALWAYS be equal to P or p.

3. When the following commands are encountered:


(3.A) A,a the fifth (5th) parameter after A or a must be any of the following: (A,
a, E, e, D, d, S, s ,P, p), otherwise, EXIT FROM THE PROGRAM.
(3.B) E,e the fourth (4th) parameter after E, or e must be any of the following: (A,
a, E, e, D, d, S, s ,P, p), otherwise, EXIT FROM THE PROGRAM.
(3.C) D,d the second (2nd) parameter after D or d must be any of the following:
(A, a, E, e, D, d, S, s ,P, p), otherwise, EXIT FROM THE PROGRAM.
(3.D) S,s the third (3rd) parameter after S or s must be any of the following: (A,
a, E, e, D, d, S, s ,P, p), otherwise, EXIT FROM THE PROGRAM.
(3.E) P,p the next parameter after P or p (if this is not the last argument) must be
any of the following: (A, a, E, e, D, d, S, s ,P, p), otherwise, EXIT FROM
THE PROGRAM.
Some examples:
java CS2 A Franz Bulacan 23 M P this is valid, hence, DO NOT EXIT FROM THE
PROGRAM.
java CS2 A Franz Bulacan 23 P this is invalid. See rule 3.A above. Hence, EXIT
FROM THE PROGRAM.
java CS2 100 P this is invalid. See rule # 1 above. Hence, EXIT FROM THE
PROGRAM.
java CS2 P P P P P this is still valid. We have no such rule for this. It simply means
print the linked list 5 times. Hence, DO NOT EXIT FROM THE PROGRAM.
java CS2 E 1 Name Franz P this is valid, hence, DO NOT EXIT FROM THE PROGRAM.
java CS2 E 1 Name P this is invalid. See rule 3.B above. Hence, EXIT FROM THE
PROGRAM.
java CS2 E 1 Name Franz Q this is invalid. See rule # 2 above. Hence, EXIT FROM
THE PROGRAM.
java CS2 D P this is invalid. See rule 3.C above. Hence, EXIT FROM THE PROGRAM.
java CS2 D P P this is valid. See rule 3.C above. Hence, DO NOT EXIT FROM THE
PROGRAM.
java CS2 S ASC Name P this is valid. See rule 3.D above. Hence, DO NOT EXIT
FROM THE PROGRAM.
java CS2 S ASC P this is invalid. See rule 3.D above. Hence, EXIT FROM THE
PROGRAM.

Type 2 Validation:

Note that the programmer must check the validations in the sequence mentioned
below.
IMPORTANT: If there are multiple errors for a certain command, just pick up the first
error then proceed immediately into the next command. Therefore, for every
command, there could only be either one error message or a successful message.
Add (A or a):
1. Check the size of the linked list. If it is already equal to 5, then proceed
immediately to the next command.
ERROR: Add failed. Maximum records present in the linked list.
2. Check the length of the Name. If it exceeds 10 characters, then proceed
immediately to the next command.
ERROR: Add failed. Name exceeds 10 characters.
3. Check for valid characters. It should be A-Z, a-z. If not, then proceed immediately
to the next command.
ERROR: Add failed. Name contains invalid characters.
4. Check the length of the Address. If it exceeds 15 characters, then proceed
immediately to the next command.
ERROR: Add failed. Address exceeds 15 characters.
5. Check for valid characters. It should be A-Z, a-z and 0-9. If not, then proceed
immediately to the next command.
ERROR: Add failed. Address contains invalid characters.
6. Check the length of the Age. If it is not exactly equal to 2 characters, then
proceed immediately to the next command.
ERROR: Add failed. Age should be exactly 2 characters in length.
7. Check for valid characters. It should be 0-9. If not, then proceed immediately to
the next command.
ERROR: Add failed. Age contains invalid characters.
8. Check for the range. Age should be 16 to 25 only, inclusive. If not, then proceed
immediately to the next command.
ERROR: Add failed. Age should be 16-25 only, inclusive.
9. Check the Gender. It should be M, m, F or f only. If not, then proceed
immediately to the next command.
ERROR: Add failed. Gender should be M, m, F or f only.
If it passes all validations above, add the record into the linked list. Also, print a
successful message.
SUCCESS: Record added successfully.
Edit (E or e):
1. Check for existing Student Number. If not, then proceed immediately to the next
command.
Note: This validation caters for the scenario when you try to edit a record but the
linked list is empty.
ERROR: Edit failed. Student Number does not exist.
2. Check for modifier. It should be Name, Address, Age or Gender. This is
NOT case-sensitive. If not, then proceed immediately to the next command.
ERROR: Edit failed. Unknown modifier.
3. If the modifier selected is equal to Name, check the length of the Name. If it
exceeds 10 characters, then proceed immediately to the next command.
ERROR: Edit failed. Name exceeds 10 characters.
4. If the modifier selected is equal to Name, check for valid characters. It should
be A-Z, a-z. If not, then proceed immediately to the next command.

ERROR: Edit failed. Name contains invalid characters.


5. If the modifier selected is equal to Address, check the length of the Address. If it
exceeds 15 characters, then proceed immediately to the next command.
ERROR: Edit failed. Address exceeds 15 characters.
6. If the modifier selected is equal to Address, check for valid characters. It should
be A-Z, a-z and 0-9. If not, then proceed immediately to the next command.
ERROR: Edit failed. Address contains invalid characters.
7. If the modifier selected is equal to Age, check the length of the Age. If it is not
exactly equal to 2 characters, then proceed immediately to the next command.
ERROR: Edit failed. Age should be exactly 2 characters in length.
8. If the modifier selected is equal to Age, check for valid characters. It should be
0-9. If not, then proceed immediately to the next command.
ERROR: Edit failed. Age contains invalid characters.
9. If the modifier selected is equal to Age, check for the range. Age should be 16
to 25 only, inclusive. If not, then proceed immediately to the next command.
ERROR: Edit failed. Age should be 16-25 only, inclusive.
10. If the modifier selected is equal to Gender, check the Gender. It should be M,
m, F or f only. If not, then proceed immediately to the next command.
ERROR: Edit failed. Gender should be M, m, F or f only.
If it passes all validations above, edit the record in the linked list. Also, print a
successful message.
SUCCESS: Record edited successfully.
Delete (D or d):
1. Check for existing Student Number. If not, then proceed immediately to the next
command.
Note: This validation caters for the scenario when you try to delete a record but
the linked list is empty.
ERROR: Delete failed. Student Number does not exist.
If it passes all validations above, delete the record in the linked list. Also, print a
successful message.
SUCCESS: Record deleted successfully.
Sort (S or s):
1. Check for first modifier. It should be ASC or DESC. This is NOT case-sensitive.
If not, then proceed immediately to the next command.
ERROR: Sort failed. Unknown first modifier.
2. Check for second modifier. It should be Number, Name, Address or Age.
This is NOT case-sensitive. If not, then proceed immediately to the next
command.
ERROR: Sort failed. Unknown second modifier.
Note: When sorting the list but the linked list is empty, simply ignore the command
then proceed immediately to the next command.
If it passes all validations above, sort the record in the linked list accordingly. ASC for
ascending and DESC for descending. Also, print a successful message.
SUCCESS: Linked list sorted successfully.

Additional Information:

Adding a record:
1. The record should ALWAYS be inserted at the back of the linked list.
2. When adding a new record in the linked list, program should use the FIRST
AVAILABLE Student # (from 1 to 5) which is not currently being used in the
linked list.
Example:
4 1 3 -> null
Since the FIRST AVAILABLE Student # is 2, the new linked list after add should
look like this:
4 1 3 2 -> null
Note that Student # 2 was inserted at the back of the linked list.
Sorting the linked list:
1. The following modifiers can be sorted either ASC (Ascending) or DESC
(Descending):
Number sort the Student #
Name sort the Student Name
Address sort the Student Address
Age sort the Student Age
2. When sorting Number (Student #):
Example:
4 1 3 2 5 null
Ascending: 1 2 3 4 5 > null
Descending: 5 4 3 2 1 > null
3. When sorting Name and Address, we compare the strings lexicographically.
Note that when we compare strings lexicographically, digits precede letters and
uppercase letters precede lowercase ones. Comparison should be NOT casesensitive.
Tip: use .compareTo() method.
Please refer to this link for a tutorial:
http://stackoverflow.com/questions/4064633/string-comparison-in-java
4. When sorting Age:
Example:
19 24 16 25 23 -> null
Ascending: 16 19 23 24 25 -> null
Descending: 25 24 23 19 16 -> null
How to sort records with duplicates:
Note: Applicable for sorting Name, Address and Age. Not applicable for Student # as
this is always unique.
Example:
Student #
Name
Ascending:

1
Franz

2
Glenda

3
Franz

4
Glenda

5
Franz

Student #
Name

1
Franz

3
Franz

5
Franz

2
Glenda

4
Glenda

2
Glenda

4
Glenda

1
Franz

3
Franz

5
Franz

Descending:
Student #
Name

Printing the contents of the linked list:


Print the data starting from the first node up to the last node
If the list is currently empty:
Empty List
If the list is not empty, print the standard format below:
Example:
<Student Number>,<Name>,<Address>,<Age>,<Gender>
1,Franz,Bulacan,25,M
2,Rico,Cavite,16,M
3,Glenda,Baguio,18,F
4,Charm,Manila,20,F
5,Ginalyn,Taguig,23,F

Sample Program Simulation and Desired Output:


Using the command prompt, assuming the name of the file is CS2.java, type the following:
java CS2 P A Franz Bulacan AE5 M A Franz Bulacan 25 M A Rico Cavite 16 M E 2 Names
Rico15 E 2 Name Nico A Glenda Baguio 18 F A Charm Manila 20 F A Ginalyn Taguig 23 F D 6
D 2 A Nico Cavite 16 M S AAA Addresses S ASC Address P S DESC Age P
Output:
Empty List
ERROR: Add failed. Age should be exactly 2 characters in length.
SUCCESS: Record added successfully.
SUCCESS: Record added successfully.
ERROR: Edit failed. Unknown modifier.
SUCCESS: Record edited successfully.
SUCCESS: Record added successfully.
SUCCESS: Record added successfully.
SUCCESS: Record added successfully.
ERROR: Delete failed. Student Number does not exist.
SUCCESS: Record deleted successfully.
SUCCESS: Record added successfully.
ERROR: Sort failed. Unknown first modifier.
SUCCESS: Linked list sorted successfully.
3,Glenda,Baguio,18,F

1,Franz,Bulacan,25,M
2,Nico,Cavite,16,M
4,Charm,Manila,20,F
5,Ginalyn,Taguig,23,F
SUCCESS: Linked list sorted successfully.
1,Franz,Bulacan,25,M
5,Ginalyn,Taguig,23,F
4,Charm,Manila,20,F
3,Glenda,Baguio,18,F
2,Nico,Cavite,16,M

Potrebbero piacerti anche