// Arup Guha
// 3/24/2026
// Grocery List example to illustrate the use of a HashSet

import java.util.*;

public class grocery {

	public static void main(String[] args) {
	
		// Add some things then print. Illustrating that apple only shows up once.
		HashSet<String> groceries = new HashSet<String>();
		groceries.add("apple");
		groceries.add("banana");
		groceries.add("apple");
		groceries.add("kiwi");
		printSet(groceries);
		
		// We call remove once and the apple is gone!
		groceries.remove("apple");
		printSet(groceries);
		
		// Test contains.
		String[] stuff = {"dragonfruit", "kiwi", "apple", "banana", "strawberry"};
		for (String x : stuff) {
			if (groceries.contains(x))
				System.out.println("Yes, we have "+x+".");
			else
				System.out.println("No, we don't have "+x+".");
		}
		
		// Now it's gone!
		groceries.clear();
		printSet(groceries);
		
		// Again illustrating the no repeats idea.
		for (String x: stuff)
			groceries.add(x);
		for (String x: stuff)
			groceries.add(x);		
		printSet(groceries);
		
		// Test size method.
		System.out.println("We have "+groceries.size()+" grocery items.");
	}
	
	// Prints each item in set on a line.
	public static void printSet(HashSet<String> set) {
		System.out.print("Set: ");
		for (String s: set)
			System.out.print(s+" ");
		System.out.println();
	}
}