Skip to content

Lesson 4 (Classes Part 2)

Courtney Frey edited this page Apr 14, 2022 · 2 revisions

Lesson 4: Classes, Part 2

In the prep work for this lesson, the students learned

  1. How to customize fields with the keywords final and static.
  2. How to add methods to a class and call those methods.
  3. The difference between instance methods and static methods.
  4. How to override the default toString and equals methods for a class.
  5. How to auto-generate an equals method using the tools in IntelliJ.

Announcements

For Part-Time Students:

  1. Graded Assignment #2 is open, and it is due soon. Keep working on your project! After today, you will have enough skill to make significant progress.

For Full-Time Students:

  • Welcome to Days 5 - 7!
  • Assignment 1 due end of Day 8
  • Day 5:
    • Lesson 4
  • Days 6 & 7:
    • Assignment 1 work days
    • Catch up days

Large Group Time (Instructor)

Lesson 4 Topics That Require Careful Attention

  1. Q&A for the prep work exercises.
  2. The words final and static can be confusing if the students take latter term to mean "unchanging". Be sure to review what each keyword means and the results of applying each one to a field.
  3. Pay particular attention to why we want to use the equals() method rather than the == operator to compare objects.
    1. Review the difference between comparing identity vs. equality.
    2. Note the default behavior of the equals method.
  4. Review why students will usually want to code their own toString and equals methods.
  5. Review how to call methods using ClassName.methodName vs. objectName.methodName.
    1. When and why does it matter which syntax to use?
  6. Review the objectives for today's studio task. Alternatively, if the TFs raise concerns about how the students are progressing on assignment 2, replace the studio intro with a review of the assignment 2 objectives.

Small Group Time: Lesson 4 Studio (TF Notes)

  1. This studio extends the restaurant menu that the students started in class 3. Today, they will create methods to add and remove menu items, as well as to print the menu.
  2. Pace the studio carefully. Just like last class, the students will begin planning their class methods using pen and paper, then pair up to share their ideas.
  3. Provide ample time for this sharing. However, the students will need more time to get their methods coded compared to the last studio, so plan accordingly.
  4. As the students get further into their coding, rotate through your group and have them demonstrate their program. Verify that they can add or remove new menu items and that they can print a menu to the screen.
  5. Just like the last studio, it is important to make sure the students' code works and matches their design.
    1. Encourage students who are not following the principles of OOP to consider how to better encapsulate their methods.
    2. If a student's code differs significantly from their design, ask them (carefully) about why they decided to adapt their plan.
Clone this wiki locally