In this lab, you will experiment with maps and sets in Java.
Download the project Lab12.zip with a class named MapSetTester with a main method. You will be using the TreeSet and HashMap classes, so open up the Java API so you can refer to the documentation for these classes as you work on these problems. (Our next lecture will cover the HashSet and HashMap classes.)
Map<______,______> networkMap = new HashMap<______,______>();
After you update the hash map, output the contents of the hash map (i.e. System.out.println(networkMap); ). This will repeat until 10 shows have been entered.
Sample Output (note how the networks are not necessarily in lexicographic order, but the television shows for each network are in lexicographic order... why? ):
TV show on FOX: The Simpsons
{FOX=[The Simpsons]}
TV show on NBC: ER
{FOX=[The Simpsons], NBC=[ER]}
TV show on ABC: 20/20
{FOX=[The Simpsons], NBC=[ER], ABC=[20/20]}
TV show on CBS: Survivor
{CBS=[Survivor], FOX=[The Simpsons], NBC=[ER], ABC=[20/20]}
TV show on ABC: Lost
{CBS=[Survivor], FOX=[The Simpsons], NBC=[ER], ABC=[20/20, Lost]}
TV show on FOX: Family Guy
{CBS=[Survivor], FOX=[Family Guy, The Simpsons], NBC=[ER], ABC=[20/20, Lost]}
TV show on CBS: CSI
{CBS=[CSI, Survivor], FOX=[Family Guy, The Simpsons], NBC=[ER], ABC=[20/20, Lost]}
TV show on FOX: American Idol
{CBS=[CSI, Survivor], FOX=[American Idol, Family Guy, The Simpsons], NBC=[ER], ABC=[20/20, Lost]}
TV show on ABC: Desperate Housewives
{CBS=[CSI, Survivor], FOX=[American Idol, Family Guy, The Simpsons], NBC=[ER], ABC=[20/20, Desperate Housewives, Lost]}
TV show on NBC: Law And Order
{CBS=[CSI, Survivor], FOX=[American Idol, Family Guy, The Simpsons], NBC=[ER, Law And Order], ABC=[20/20, Desperate Housewives, Lost]}
Sample output:
ABC: [20/20, Desperate Housewives, Lost] CBS: [CSI, Survivor] FOX: [American Idol, Family Guy, The Simpsons] NBC: [ER, Law And Order]
HINT: Write a method that uses the map to lookup the network for a TV show: Iterate over each key (network) in the map, and see if its value (set of shows) contains the desired show. If so, return the network. If the TV show is not in the map return null. You don't have to worry about uppercase/lowercase, just match the TV show name exactly.