--- tags: Setup --- # Lecture 6 Setup/Prep This lecture will cover three topics: - Updating values stored in fields - Showing how field updates interact with the environment and the heap - Discussing what it means for two objects to be "equal" We will work with the following two classes. During lecture, we will add a method to update the room in which a Course meets. ``` public class Course { String dept; int number; String room; public Course(String dept, int num, String rm) { this.dept = dept; this.number = num; this.room = rm; } } public class Student { String name; Course course1; public Student(String name, Course c) { this.name = name; this.course1 = c; } } ``` There are a couple of different ways we could update the room for a course, and they have different implications for how our code behaves. We will study those implications using the following test class (note: this won't compile yet because we haven't yet written `newRoom`): ``` public class RegistrarTest { public RegistrarTest(){} public static void main(String[] args) { Course cs18 = new Course("csci", 18, "BERT 130"); Student mary = new Student("mary smith", cs18); Student ari = new Student("ari aman", cs18); cs18.newRoom("SAL 001"); Student li = new Student("wang li", cs18); System.out.println(li.course1.room); } } ``` ## Prep Familiarize yourself with these classes so we can get right to work using them. Also, be prepared with a way to draw memory layouts (whether on paper or a drawing tool) -- we'll be doing a decent bit of drawing-based work during lecture. If you want to think ahead a bit, draw out the environment and heap contents that would be in place before the call to `newRoom` when running the `main` method in the test class (we will do this together during lecture as well).