0% found this document useful (0 votes)
8 views5 pages

The Set

This lesson introduces the concept of Sets as an advanced data structure that stores unique elements without duplicates, similar to mathematical sets. It includes an example application demonstrating Set operations and a DIY project for creating a classlist management application for a teacher, ensuring no duplicate students. The lesson concludes with a summary of the key concepts covered.

Uploaded by

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

The Set

This lesson introduces the concept of Sets as an advanced data structure that stores unique elements without duplicates, similar to mathematical sets. It includes an example application demonstrating Set operations and a DIY project for creating a classlist management application for a teacher, ensuring no duplicate students. The lesson concludes with a summary of the key concepts covered.

Uploaded by

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

Lesson: The Set

Author: Vuyisile Memani

Date: 27 August 2023

Introduction

In this lesson we introduce the student to the concept of Sets. We explain the concept, follow that up
with an example and conclude with an exercise for the student to do.

What is a set?

A set is an advanced data structure that stores unique reference elements. It doesn’t allow duplicates
to be stored. It behaves the same way as your old mathematical set concept learnt at high school.

Technically, the map is represented by the Set interface. The interface is located in the [Link]
package. The interface has several sub interfaces and classes that implement the interface. The figure
below the inheritance hierarchy of the Set interface.

As can be seen, the Set interface uses generics, Set<E>. The <E> could be an object of any type. One
of the known specific types of Sets is a HashSet. Some of the methods defined by a Set are shown in
the next page.

1
Let us take an example to demonstrate the implementation of the Set interface.

Example

Create an application that will implement the following Set: [1, 2, 3, 4, 5].

The application must perform the following operations on a Queue:

• Add elements to a set.


• Display all the elements.
• Attempt to add a duplicate.
• Remove a specific element.
• Search for a specific element.
• Clear a set.

2
Solution

• Create a Java application called SetExample.

• Write the code

3
• Test the code.

4
DIY

Mulumba is a teacher by profession. He needs a console-based desktop application that he can use to
manage his classlist. His classlist consists of students. A student has a name, surname, student number
and a list of subjects done. Part of the system requirements is that he doesn’t want to have duplicates
in his classlist, that is, the same student appearing more than once in the classlist.

Mulumba approaches you with a request to create for him the application with the following
functionalities:

• Allow him to add a student in the classlist. No duplicates are allowed.


• Display the details of all the students in the classlist.
• Remove a student from the classlist.
• Search for a student.
• Update the details of a student. You can decide which part to update.
• Store the contents of the list in a text file.

Create such an application for Mulumba.

Conclusion

In this presentation we managed to introduce the student to the concept of Sets. We explained the
concept, did an example and concluded with an exercise for the student to do.

Thank you very much for having taken time to go through this lesson. Enjoy the rest of your day and
God bless you.

You might also like