Activity: Master Java List Data Structure

Deadline: October 4, 2024
Activity Type: Coding
Goal: Understand and apply the list data structure for various data sets.


Overview:

In this activity, you will practice using lists to store and manage multiple instances of objects like Product, Employee, Books, University, and Restaurant. You will create lists for these objects and populate them with details (e.g., names, prices, job titles). This activity is designed to help you understand how to manage collections of data in a structured manner.

This is a follow-up to Activity 16

Check this:

ACTIVITY (hashnode.space)


Instructions:

  1. Create the following Java classes:

    • Product: Store product details (e.g., product name, price).

    • Employee: Store employee details (e.g., name, job title).

    • Books: Store book details (e.g., title, author).

    • University: Store university details (e.g., name, location).

    • Restaurant: Store restaurant details (e.g., name, cuisine type).

  2. Use Lists to store the details of each class:

    • Create lists for each object (e.g., list of product names, list of prices, list of employee job titles, etc.).

    • Populate the lists with at least 5 entries per object.

  3. Access and print the details from the lists.


Example Using Lists:

Below is an example of how you can structure your data using lists for students, similar to the data you provided in the image:

Example: Student Data Using Lists

import java.util.ArrayList;

public class StudentListExample {
    public static void main(String[] args) {
        // List of student names
        ArrayList<String> student_name_list = new ArrayList<>();
        student_name_list.add("Juan Carlos");
        student_name_list.add("Jose Rizal");
        student_name_list.add("Juan Luna");
        student_name_list.add("Andres Bonifacio");
        student_name_list.add("Justin Bieber");
        student_name_list.add("Michael Jordan");
        student_name_list.add("Andrew Jordan");
        student_name_list.add("Jessa Boe");
        student_name_list.add("Ted Talk");

        // List of student sections
        ArrayList<String> student_section_list = new ArrayList<>();
        student_section_list.add("BSIT-4B");
        student_section_list.add("BSIT-2A");
        student_section_list.add("BSIT-3A");
        student_section_list.add("BSIT-3A");
        student_section_list.add("BSIT-2A");
        student_section_list.add("BSIT-4A");
        student_section_list.add("BSIT-4A");
        student_section_list.add("BSIT-2B");
        student_section_list.add("BSIT-3B");

        // List of student IDs
        ArrayList<Integer> student_id_list = new ArrayList<>();
        for (int i = 1; i <= 9; i++) {
            student_id_list.add(i);
        }

        // List of student emails
        ArrayList<String> student_email_list = new ArrayList<>();
        student_email_list.add("juan@gmail.com");
        student_email_list.add("jose@gmail.com");
        student_email_list.add("juanl@gmail.com");
        student_email_list.add("andres@gmail.com");
        student_email_list.add("justin@gmail.com");
        student_email_list.add("michael@gmail.com");
        student_email_list.add("andrew@gmail.com");
        student_email_list.add("jessa@gmail.com");
        student_email_list.add("ted@gmail.com");

        // Print student data
        for (int i = 0; i < student_name_list.size(); i++) {
            System.out.println("ID: " + student_id_list.get(i) + ", Name: " + student_name_list.get(i) + ", Section: " + student_section_list.get(i) + ", Email: " + student_email_list.get(i));
        }
    }
}

Tasks:

  1. Define lists for storing data related to the classes: Product, Employee, Books, University, and Restaurant.

  2. Populate the lists with data for each class, ensuring there are at least 5 entries.

  3. Access and print the details of each object from the list.


Submission:


Deadline:

The submission is due on October 4, 2024.

Updated on