Practical Coding in Java

Learn to write and validate your own code

Darren Kessner, PhD

(revised January 9, 2026)

Previous: CrazyPetOwner

Coding Exercises: Composition

Make sure to write test code (not necessarily full unit tests) to make sure your functions are behaving properly.

ShapeCollection

  1. Write a Shape class, with private variables for name and number of sides, constructor, and accessor functions.

  2. Write a ShapeCollection class, which has a private ArrayList of Shape objects. Include the following:

AcademicClass

  1. Write a Student class, with private variables for name and favorite number (integer), including constructor and accessor functions.
  1. Write a Teacher class, with private variables for name and subject, including constructor and accessor functions.

  2. Write a class AcademicClass, representing a course you take in school. The AcademicClass should have a private variable for the teacher, and a private ArrayList of students. Either include the teacher in the constructor or write a setTeacher() function. Also include the following:


Next: