Skip to content

Instantly share code, notes, and snippets.

@AntonyMRuiz
Last active September 24, 2025 20:07
Show Gist options
  • Save AntonyMRuiz/79126db14e9e67f94ef3b04ccb3b7202 to your computer and use it in GitHub Desktop.
Save AntonyMRuiz/79126db14e9e67f94ef3b04ccb3b7202 to your computer and use it in GitHub Desktop.

Feature: Java Basics with OOP, Collections, and Maps

Description: The system should allow practicing core Java concepts by modeling simple classes, creating objects, managing lists of elements, applying inheritance and polymorphism, and using maps to store and count data. Students will build small examples where they define classes, instantiate objects, store them in an ArrayList, use a HashMap for quick lookups and counters, and demonstrate polymorphism through inheritance.

Acceptance Criteria:

  • Scenario: Create and print objects Given a class with attributes and a constructor When I instantiate multiple objects Then I can print their values on the console.

  • Scenario: Manage a list of objects Given an ArrayList with several elements When I iterate through the list Then I can filter or display only the matching items.

  • Scenario: Store key-value pairs Given a HashMap initialized in the program When I insert multiple key-value entries Then I can search by key and retrieve the corresponding value.

  • Scenario: Demonstrate inheritance and polymorphism Given a parent class and two subclasses overriding a method When I add them to an ArrayList of the parent type Then each object executes its own version of the method when called.

  • Scenario: Count repeated elements Given a list with repeated words When I process them into a HashMap Then the output shows each word with its correct frequency count.

Activity 1 – Basic class and objects

  1. Create a class Person with attributes name and age.
  2. Add a constructor, getters, and setters.
  3. In main, create 3 Person objects and print them on the console.

Activity 2 – List of objects

  1. Reuse the Person class.
  2. Create an ArrayList<Person> in main.
  3. Add the 3 people created before.
  4. Loop through the list with a for-each and print only those who are adults (age ≥ 18).

Activity 3 – Simple agenda with HashMap

  1. Create a class Agenda.
  2. Inside it, declare a HashMap<String, String> (key = name, value = phone).
  3. Add 3 contacts from main.
  4. Search a contact by name and print the phone number.

Activity 4 – Simple inheritance

  1. Create a base class Animal with a method makeSound().

  2. Create two subclasses: Dog and Cat.

    • Dog prints “Woof”.
    • Cat prints “Meow”.
  3. In main, store the animals in an ArrayList<Animal> and loop calling makeSound().


Activity 5 – Word counter

  1. Declare a HashMap<String, Integer>.
  2. Insert words from an ArrayList<String>.
  3. Count how many times each word appears.
  4. Print the result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment