JAVA 2.1 Navi
JAVA 2.1 Navi
Experiment 2.1
• 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.
• Procedure/Algorithm/Pseudocode:
1. Import the Scanner class from the java.util package.
2. Define a custom exception class named InvalidValueException that
extends Exception.
3. Define an abstract class named Account with an abstract method
calculateInterest().
4. Define concrete classes SavingsAccount, FDAccount, and RDAccount
that extend the Account class.
5. Implement the calculateInterest() method in each concrete class to
calculate interest based on specific criteria.
6. Define a class named InterestCalculator.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
• Code:
import java.util.*;
return number;
}
if (cardMap.containsKey(symbol)) {
cardMap.get(symbol).add(card);
} else {
List<Card> cards = new ArrayList<>(); cards.add(card);
cardMap.put(symbol, cards);
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
}
System.out.println();
scanner.close();
}
}
Result/Output:
1. Number of Cards Entered and its Sum
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Learning Outcomes:
1. Demonstrates efficient use of data structures like Map for grouping data.
2. Illustrates dynamic input handling and processing.
3. Highlights importance of iterating over collections for data manipulation.
4. Shows sorting behavior with TreeMap for alphabetical order.
5. Encourages encapsulation and object-oriented design principles with
Card class.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING