Java 2.2 Sam Final

You might also like

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: Samarth Maheshwari UID: 21BCS10260
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(“SAMARTH MAHESHWARI 21BCS10260”);
Set<Set<Character>> cards = new HashSet<>();
cards.add(Set.of('1', '2', '3'));
cards.add(Set.of('4', '3', '5'));
cards.add(Set.of('5', '6', '7'));
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