// Arup Guha
// 3/25/2026
// Example code to show how to use a HashMap

import java.util.*;

public class TestHashMap {

	public static void main(String[] args) {
	
		// Creates a HashMap.
		HashMap<String,Integer> numSibs = new HashMap<String,Integer>();
		
		// Places an entry in the map.
		numSibs.put("Arup", 3);
		
		// Returns the number of siblings Arup has.
		Integer ans = numSibs.get("Arup");
		System.out.println(ans);
		
		// Here's how to handle searching for a key that doesn't exists.
		Integer ans2 = numSibs.get("Bob");
		if (ans2 == null)
			System.out.println("There's no entry for Bob.");
		
		/*** This will crash the program.
		int tryagain = numSibs.get("Bob");
		***/
		
		// Works to overwrite a value in the map.
		numSibs.put("Arup", 2);
		System.out.println(numSibs.get("Arup"));
		
		// Put more stuff in the map.
		numSibs.put("OnlyChild", 0);
		numSibs.put("Jace", 1);
		numSibs.put("BigFamily", 13);
		
		String[] keys = {"Janice", "Arup", "Bob", "OnlyChild", "onlyChild", "BigFamily", "Bruno"};
		
		// Try this out for some strings.
		for (String k: keys) {
			
			// Safe to look up k in map.
			if (numSibs.containsKey(k))
				System.out.println(k+" has "+numSibs.get(k)+" brothers and sisters.");
			
			// k's not there so I print an error message.
			else
				System.out.println("I have no information about "+k+".");
		}
		
		// Here is how to loop through each key in a map
		int total = 0;
		System.out.println("\nFull listing of the map.");
		for (String k : numSibs.keySet()) {
			System.out.println(k+" has "+numSibs.get(k)+" brothers and sisters.");
			total += numSibs.get(k);
		}
		System.out.println("The total # of sibs is "+total);
		System.out.println("The total # of people involved is "+(total+numSibs.size()));
		
		// How to remove an entry.
		numSibs.remove("BigFamily");
		
		// Proving removal.
		System.out.println("\nReprint after removal.");
		for (String k : numSibs.keySet()) 
			System.out.println(k+" has "+numSibs.get(k)+" brothers and sisters.");
	}
}