import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Lab8 {
    public static void main(String[] args) {

        System.out.println("||==========================================||");
        System.out.printf("|| %-40s ||%n","Student Name: Faisal Majed Alghamdi");
        System.out.printf("|| %-40s ||%n","Student Number: 447001625");
        System.out.println("||==========================================||");
        System.out.println("||==========================================||");
        System.out.printf("|| %-40s ||%n","Student Name: Ammar");
        System.out.printf("|| %-40s ||%n","Student Number: ");
        System.out.println("||==========================================||\n\n\n");

        Scanner input = new Scanner(System.in);
        HashMap<Integer, String> map = new HashMap<>();

        int key;
        String value;
        int choice = 0;

        while (choice != 5) {
            System.out.println("======Menu======");
            System.out.println("1. Insert");
            System.out.println("2. Update");
            System.out.println("3. Delete");
            System.out.println("4. Print");
            System.out.println("5. Exit");
            System.out.print("choose an option: ");

            choice = input.nextInt();
            input.nextLine();
            switch (choice) {
                case 1:
                    System.out.print("enter key: ");
                    key = input.nextInt();
                    input.nextLine();

                    if (map.containsKey(key)) {
                        System.out.println("key already exists");
                    } else {
                        System.out.print("enter value: ");
                        value = input.nextLine();
                        map.put(key, value);
                        System.out.println("added");
                    }
                    break;

                case 2:
                    System.out.print("enter key to update: ");
                    key = input.nextInt();
                    input.nextLine();

                    if (map.containsKey(key)) {
                        System.out.print("enter new value: ");
                        value = input.nextLine();
                        map.put(key, value);
                        System.out.println("updated");
                    }
                    else {
                        System.out.println("key not found");
                    }
                    break;

                case 3:
                    System.out.print("enter key to delete: ");
                    key = input.nextInt();

                    if (map.containsKey(key)) {
                        map.remove(key);
                        System.out.println("deleted");
                    } else {
                        System.out.println("key not found");
                    }
                    break;

                case 4:
                    if (map.isEmpty()) {
                        System.out.println("hashmap is empty");
                    } else {
                        for (var entry : map.entrySet()) {
                            System.out.println("key = " + entry.getKey() + ", value = " + entry.getValue());
                        }
                    }
                    break;

                case 5:
                    break;

                default:
                    System.out.println("invalid option");
            }
        }

        input.close();
    }
}