Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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.
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.
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
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