Unit 5 – Writing Classes – in AP® Computer Science A is one of my absolute favorites to teach. I feel like this is where several things start to come together and the students feel like they are REALLY coding. But, I have found out that it seems to be where the confusion really starts to rear its ugly head. So, to help with the understanding and clear this confusion, I created an AP® Computer Science A project called “Class Creation Project: The Turkey Class“.
The Objectives
In the Course Exam & Description document, there are several objectives for Unit 5 and this project hits several:
- Mod-2.A – Designate access and visibility constraints to classes, data, constructors, and methods.
- Mod-3.A – Designate private visibility of instance variables to encapsulate the attributes of an object.
- Mod-2.B – Define instance variables for the attributes to be initialized through the constructors of a class.
- Mod-2.D – Define behaviors of an object through non-void methods without parameters written in a class.
- Mod-2.E – Define behaviors of an object through void methods with or without parameters written in a class.
- Mod-2.F – Define behaviors of an object through non-void methods with parameters written in a class.
The Materials Needed
- Marshmallows – At least 2 per student
- Pretzel Sticks – Best way to hold the turkey together
- Jolly Ranchers – Different colors for the tail feathers
- The driver program, class definition, and PowerPoint files
The Assignment
Students are to write an entire class definition representing a turkey. They must write the instance data, a default constructor, a parameterized constructor, three accessor methods, three mutator methods, and a toString method. The worksheet provided will have the class definition already sectioned out and will reinforce vocabulary, too.
Once the class definition is complete, they must fill in the driver program with the directions given of instantiating a turkey and using several methods to change the turkey.
The assignment takes roughly 90 minutes to do from start to finish.
The Fun Part
Once the students finish the class definition and driver program, I have them create a turkey from marshmallows, pretzel sticks, and jolly ranchers. This is the funnest part! The excitement on the students faces is so awesome to see!
They are to create it, name it, take a picture and upload it to Google Classroom. It is so cool to see the different turkeys they come up with!
The Product
Here is an example of what the students could make.
The Conclusion
Do you have your students do something similar? If so, I am curious to know what.