From 32dd7d3494747464f68472849fe0e692ee87f180 Mon Sep 17 00:00:00 2001 From: "Andrei Jiroh Halili (STI College Meycauayan)" Date: Tue, 20 Oct 2026 08:30:08 +0800 Subject: [PATCH] iykyk another output another commit OOOOOOOOOOOOOHHHHHHH DIIIIIIIIIIIIIIIIIIIIIIIIIIIP!!! (IYKYK Verplexism) Signed-off-by: Andrei Jiroh Halili (STI College Meycauayan) --- .../projects/dsaLabs/HashMapLab.java | 24 ++++++ .../projects/dsaLabs/StudentDirectory.java | 84 +++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 java/src/dev/andreijiroh/studentops/projects/dsaLabs/HashMapLab.java create mode 100644 java/src/dev/andreijiroh/studentops/projects/dsaLabs/StudentDirectory.java diff --git a/java/src/dev/andreijiroh/studentops/projects/dsaLabs/HashMapLab.java b/java/src/dev/andreijiroh/studentops/projects/dsaLabs/HashMapLab.java new file mode 100644 index 0000000..aee34ca --- /dev/null +++ b/java/src/dev/andreijiroh/studentops/projects/dsaLabs/HashMapLab.java @@ -0,0 +1,24 @@ +package dev.andreijiroh.studentops.projects.dsaLabs; +import java.util.HashMap; + +public class HashMapLab { + public static void main(String[] args) { + HashMap hashTable = new HashMap<>(); + + hashTable.put("apple", 10); + hashTable.put("banana", 20); + hashTable.put("grape", 30); + + System.out.println("apple: " + hashTable.get("apple")); + System.out.println("banana: " + hashTable.get("banana")); + + if (hashTable.containsKey("cherry")) { + System.out.println("cherry: " + hashTable.get("cherry")); + } else { + System.out.println("cherry not found!"); + } + + hashTable.remove("grape"); + System.out.println("Hash table contents: " + hashTable); + } +} \ No newline at end of file diff --git a/java/src/dev/andreijiroh/studentops/projects/dsaLabs/StudentDirectory.java b/java/src/dev/andreijiroh/studentops/projects/dsaLabs/StudentDirectory.java new file mode 100644 index 0000000..a3b986a --- /dev/null +++ b/java/src/dev/andreijiroh/studentops/projects/dsaLabs/StudentDirectory.java @@ -0,0 +1,84 @@ +package dev.andreijiroh.studentops.projects.dsaLabs; +import java.util.HashMap; +import java.util.Scanner; + +/** + * 05 Laboratory Exercise 1 - Data Structures and Algorithms + * + * @author Andrei Jiroh Halili (STI College Meycauayan) + * @see https://gitlab.com/andreijiroh-dev/labs/studentops-codelab/-/blob/main/java/src/dev/andreijiroh/studentops/projects/dsaLabs/StudentDirectory.java + */ +public class StudentDirectory { + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + HashMap studentList = new HashMap<>(); + + System.out.print("Enter number of students: "); + Integer n = input.nextInt(); + input.nextLine(); + + for (int i = 0; i < n; i++) { + System.out.print("Enter student number: "); + String studNum = input.nextLine(); + + System.out.print("Enter student name: "); + String studName = input.nextLine(); + + studentList.put(studNum, studName); + } + + System.out.println("Student directory: " + studentList); + + do { + System.out.println("Choose an operation:\n1 - Search, 2 - Remove 3 - Add/Update, 4 - Exit"); + System.out.print("Enter your choice: "); + Integer choice = input.nextInt(); + input.nextLine(); + + switch (choice) { + case 1: + System.out.print("Enter student number to search: "); + String searchNum = input.nextLine(); + + if (studentList.containsKey(searchNum)) { + System.out.println("Student name: "+ studentList.get(searchNum)); + } else { + System.out.println("No record found with that student ID"); + } + break; + case 2: + System.out.print("Enter student number to search: "); + String removeNum = input.nextLine(); + + if (studentList.containsKey(removeNum)) { + System.out.println("Removed student "+ studentList.get(removeNum)); + studentList.remove(removeNum); + System.out.println("Updated student directory: " + studentList); + } else { + System.out.println("No record found with that student ID"); + } + break; + case 3: + System.out.print("Enter student number to add or update: "); + String newNum = input.nextLine(); + System.out.print("Student name: "); + String newName = input.nextLine(); + + if (studentList.containsKey(newNum)) { + studentList.replace(newNum, newName); + System.out.println("Existing record found. Updated existing entry"); + } else { + studentList.putIfAbsent(newNum, newName); + System.out.println("No existing record found. Added new entry"); + } + System.out.println("Updated student directory: " + studentList); + break; + case 4: + input.close(); + System.exit(0); + default: + System.out.println("Unsupported choice selection"); + } + } while (true); + } +} -- 2.54.0