0% found this document useful (0 votes)
11 views2 pages

Java 2.2 Sam Final

The document describes a Java program that collects unique symbols from a set of cards. The program uses a CardSet interface and UniqueSymbolsCollector class to store cards in a Set and return all unique symbols from the cards.

Uploaded by

Hardik
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)
11 views2 pages

Java 2.2 Sam Final

The document describes a Java program that collects unique symbols from a set of cards. The program uses a CardSet interface and UniqueSymbolsCollector class to store cards in a Set and return all unique symbols from the cards.

Uploaded by

Hardik
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/ 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