DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Experiment 1.4
Student Name: Sushmit Singh UID: 22BCS17177
Branch: CSE Section: IOT_630-B
Semester: 6th DOP: 13/01/25
Subject: Java Subject Code:22CSH-359
Aim Create a program to collect and store all the cards to assist
the users in finding all the cards in a given symbol using Collection
interface.
Algorithm:
1. Start
2. Create a collection to store cards (e.g., List<Card>).
3. Add sample cards to the collection:
o Each card has a symbol (e.g., Hearts, Diamonds) and a value (e.g., Ace,
King, 10).
4. Display all the cards in the collection:
o Iterate through the collection and print each card.
5. Prompt the user to enter a symbol to search (e.g., Hearts, Diamonds, Clubs,
Spades).
6. Read the symbol input from the user.
7. Search the collection for cards with the given symbol:
o Iterate through the collection.
o For each card, check if its symbol matches the user's input (case-
insensitive).
o If a match is found, add the card to the result list or print it directly.
8. If no cards are found for the given symbol:
o Display a message: "No cards found with symbol '<symbol>'."
9. If cards are found:
o Display all the cards with the given symbol.
[Link]
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Code:
import [Link].*;
class Card {
private String symbol;
private String value;
public Card(String symbol, String value) {
[Link] = symbol;
[Link] = value;
}
public String getSymbol() {
return symbol;
}
public String getValue() {
return value;
}
@Override
public String toString() {
return value + " of " + symbol;
}
}
public class CardCollection {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
List<Card> cards = new ArrayList<>();
[Link](new Card("Hearts", "Ace"));
[Link](new Card("Diamonds", "King"));
[Link](new Card("Clubs", "Queen"));
[Link](new Card("Spades", "Jack"));
[Link](new Card("Hearts", "10"));
[Link](new Card("Diamonds", "9"));
[Link](new Card("Clubs", "8"));
[Link](new Card("Spades", "7"));
[Link]("All Cards in Collection:");
for (Card card : cards) {
[Link](card);
}
[Link]("\nEnter a symbol to find all cards (e.g., Hearts, Diamonds, Clubs, Spades):
");
String symbol = [Link]().trim();
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
[Link]("\nCards with symbol '" + symbol + "':");
boolean found = false;
for (Card card : cards) {
if ([Link]().equalsIgnoreCase(symbol)) {
[Link](card);
found = true;
}
}
if (!found) {
[Link]("No cards found with symbol '" + symbol + "'.");
}
[Link]();
}
Output:
Learning Outcomes:
1. Demonstrate: Apply key concepts to real-world scenarios to showcase understanding.
2. Analyze: Critically evaluate information, identify patterns, and draw meaningful
conclusions.
3. Create: Develop original work, including presentations, reports, or projects, to exhibit
comprehension and skills.
4. Communicate: Convey ideas and findings effectively through oral and written
communication.
5. Collaborate: Contribute to group projects and exhibit strong teamwork capabilities in a
collaborative environment.