5.1-5.3 Popcorn Hacks

Hacks

5.1-5.3 Hacks

POPCORN HACKS: 0.2

Create a simple To-Do List that utilizes the following (0.8):

  1. Private and Public Declaration

  2. Constructor

  3. Mutable Array containing To-Do List Items

Make sure to add descriptive comments that are describing your code!

import java.util.ArrayList;

public class ToDoList {
    // Private member variables
    private String ownerName;
    private ArrayList<String> tasks;

    // Constructor to initialize the To-Do List with an owner's name
    public ToDoList(String ownerName) {
        this.ownerName = ownerName;
        tasks = new ArrayList<>();
    }

    // Public method to add a task to the To-Do List
    public void addTask(String task) {
        tasks.add(task);
    }

    // Public method to remove a task from the To-Do List
    public void removeTask(String task) {
        tasks.remove(task);
    }

    // Public method to display the owner's name and all tasks in the To-Do List
    public void displayToDoList() {
        System.out.println("To-Do List for " + ownerName + ":");
        for (String task : tasks) {
            System.out.println("- " + task);
        }
    }

    public static void main(String[] args) {
        // Create a To-Do List for a specific owner
        ToDoList myToDoList = new ToDoList("Theo");

        // Add tasks to the To-Do List
        myToDoList.addTask("Buy groceries");
        myToDoList.addTask("Finish homework");
        myToDoList.addTask("Go to gym");

        // Display the To-Do List
        System.out.println("Initial To-Do List:");
        myToDoList.displayToDoList();

        System.out.println();

        // Remove a task from the To-Do List
        System.out.println("Updated To-Do List:");
        myToDoList.removeTask("Finish homework");

        // Display the updated To-Do List
        myToDoList.displayToDoList();
    }
}

ToDoList.main(null)
Initial To-Do List:
To-Do List for Theo:
- Buy groceries
- Finish homework
- Go to gym

Updated To-Do List:
To-Do List for Theo:
- Buy groceries
- Go to gym

5.9-5.10 Hacks

POPCORN HACKS: 0.2

Write a two sentence reflection on the social and ethical implications of programming. (0.8)

Coding will often negativly affect your social implications. For example, if you are coding for a long time, you will not be able to spend time with your friends and family. Coding can also affect your ethical implications. For example, if you are coding a game, you might have to make a decision on whether or not to add a feature that might be monetarly aggresive to some people.

Popcorn Hacks

I did them in the other notebooks, not trying to combine them all into one