Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 2.2
Student Name: Harsh Sangtani UID: 21BCS10202
Branch: BE-CSE Section: 21BCS_SC-906 (A)
Semester: 6th Date of Performance: 26-02-2024
Subject Name: Java Lab Subject Code: 21CSP-319

1. Aim:
Create a program to collect unique symbols from a set of cards using set
interface.

2. Objective:
Write a java program to collect and store all the cards to assist the users in finding
all the cards in a given symbol using Collection interface.

3. Algo. /Approach:

import java.util.*;
interface CardSet {
Set<Character> collectUniqueSymbols();
}
class UniqueSymbolsCollector implements CardSet {
private Set<Set<Character>> cards;
public UniqueSymbolsCollector(Set<Set<Character>> cards) {
this.cards = cards;
}
public Set<Character> collectUniqueSymbols() {
Set<Character> uniqueSymbols = new HashSet<>();
for (Set<Character> card : cards) {
uniqueSymbols.addAll(card);
}
return uniqueSymbols;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

}
public class Main {
public static void main(String[] args) {
System.out.println(“HARSH SANGTANI 21BCS10202”);
Set<Set<Character>> cards = new HashSet<>();
cards.add(Set.of('a', 'b', 'c'));
cards.add(Set.of('d', 'a', 'c'));
cards.add(Set.of('e', 'f', 'a'));
CardSet cardSet = new UniqueSymbolsCollector(cards);
Set<Character> uniqueSymbols = cardSet.collectUniqueSymbols();
System.out.println("Unique symbols collected from the set of cards: " +
uniqueSymbols);
}
}

4. Output:

You might also like