PBLJ 2.1
PBLJ 2.1
PBLJ 2.1
Experiment 2.1
Aim:
Collect and Group Cards
Write a program to collect and store all the cards to assist the users in finding all the cards in
a given
symbol.
This cards game consist of N number of cards. Get N number of cards details from the user
and store
the values in Card object with the attributes symbol and number.
Store all the cards in a map with symbol as its key and list of cards as its value. Map is used
here to
easily group all the cards based on their symbol.
Once all the details are captured print all the distinct symbols in alphabetical order from the
Map. For
each symbol print all the card details, number of cards and their sum respectively.
Code:
package com.company;
import java.util.*;
if(mapObj.containsKey(symbol)){
valueList = mapObj.get(symbol);
valueList.add(value);
}else{
valueList = new ArrayList<Integer>();
valueList.add(value);
mapObj.put(symbol, valueList);
}
}
}
System.out.println();
Result / Output: