HW 2: Collections

Due Date 6/25/2025 11:59 PM

Using Collections

  • Create a `Product` class.
  • Define two properties: `name` and `weight` with appropriate data types and access modifiers.
  • Create a constructor to initialize these properties.
  • Define two methods, `getName()` and `getWeight()`, to return the `name` and `weight`, respectively.
  • Override the `toString()` method to return the product name and weight.

In the Main Class:

  • Create 4 instances (objects) of the `Product` class, passing the necessary values.
  • Create an `ArrayList` collection.
  • Add the 4 objects to the `ArrayList`.
  • Use a `for` loop to print the `ArrayList` collection.
  • Use the `remove()` method to delete a single object from the collection.
  • Use a `for` loop to print the updated `ArrayList`.
  • Call a method to check whether the removed object exists or not.
  • Call the `getName()` and `getWeight()` methods from your `Product` class and print the results.

Sample Output:

Sample Output

How to Submit Homework?

  • Add your full name and email at the top of the file using a comment tag.
  • Compile and run your program, entering the required inputs.
  • Take a screenshot of the result.
  • Zip your project with the source code, then upload it to Blackboard.
  • Upload the screenshot to Blackboard.

Note: Submit the assignment on Blackboard by the due date. Email and late submissions will not be accepted.