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

Java 22 Hs

The document describes a Java program that collects unique symbols from a set of cards using a Set interface. The program defines a CardSet interface with a collectUniqueSymbols method. It then implements this interface in a UniqueSymbolsCollector class which iterates through the cards Set and adds all characters to a uniqueSymbols Set to return all unique symbols.

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)
20 views

Java 22 Hs

The document describes a Java program that collects unique symbols from a set of cards using a Set interface. The program defines a CardSet interface with a collectUniqueSymbols method. It then implements this interface in a UniqueSymbolsCollector class which iterates through the cards Set and adds all characters to a uniqueSymbols Set to return all unique symbols.

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: Hardik Singh UID: 21BCS10108
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