0% found this document useful (0 votes)
30 views

Lab 6

Uploaded by

haingoc0217
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Lab 6

Uploaded by

haingoc0217
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Workshop #6: Collection framework

Learning Outcomes:

Upon successful completion of this workshop, you will have demonstrated the abilities
to:

● Practice the ArrayList class.


● Practice some basic functions : add, update, remove, display, search,… in the list
● Describe to your instructor what you have learned in completing this workshop.

Total: [10 points]

In this demonstration, ArrayList is used to store a list of students. Student details


include: Code, name, mark. A menu is supported for user choosing one operation at a
time:

(1) Add new student

(2) Search a student based on his/her code

(3) Update name and mark of a student based on his/her code

(4) Remove a student based on his/her code

(5) List all students.

Constraints:

Student code must be in format <S000>, 0 is a digit.

Student name can not be blank

Mark: 0..10

Design:

1
Implement:

2
3
4
5
6
7
Test cases

Run the program, the following menu allows user to choose one operation at a time:

Student managing Program


1-Add new student
2-Search a student
3-Update name and mark
4-Remove a student
5-List all
6-Quit
Choose 1..6:

Test case Option Input and Result


1 2 No input,

8
Output: Message: Empty list. No search can be performed!
2 3 No input,
Output: Message: Empty list. No update can be performed!
3 4 No input.
Output: Message: Empty list. No remove can be performed!
4 5 No input.
Output: Message: Empty list!
5 1 Input code : ABC/ A1234/ S12345/S001.
Input name: blank/ James
Input mark: -2/12/7
Message: Student S001 has been added.
6 2 Add: S008, Jack, 5
7 3 Add: s004,monica, 8
8 5 Output:
Student list:
S001, JAMES, 7
S008, JACK, 5
S004, MONICA, 8
Total: 3 student(s).
9 2 Input student code for search: Input S123
Output: Student S123 doesn't exist!
10 2 Input student code for search: Input s008
Output: Found: S008, JACK, 5
11 3 Input code of updated student: Input S123
Output: Student S123 doesn't exist!
12 3 Input code of updated student: Input s008
Old name: JACK, new name: input bill
Old mark: 5, new mark 0..10: input 10
Output: Student s008 has been updated.
13 5 Output:
Student list:
S001, JAMES, 7
S008, BILL, 10
S004, MONICA, 8
Total: 3 student(s).
14 4 Input code of removed student: Input s123
Output: Student s123 doesn't exist!
15 4 Input code of removed student: Input s008
Output: Student s008 has been removed.
16 5 Output:
Student list:
S001, JAMES, 7
S004, MONICA, 8
Total: 2 student(s).

9
10

You might also like