110 likes | 199 Views
Announcements Exam: 2/28 5:30-7:30pm GEO 2.216 Brief study guide on web (see detailed schedule). Last Time: arrays of objects Items[] apples; appleTypes = 8; apples = new Items[appleTypes]; apples[0] = new Items(”Granny Smith", 22);. Announcements & Review.
E N D
Announcements Exam: 2/28 5:30-7:30pm GEO 2.216 Brief study guide on web (see detailed schedule) Last Time: arrays of objects Items[] apples; appleTypes = 8; apples = new Items[appleTypes]; apples[0] = new Items(”Granny Smith", 22); Announcements & Review Lecture 16: Visualizing and Using Arrays
Initializing Array of Objects Items[] apples = new Items[3]; apples -> null null null Lecture 16: Visualizing and Using Arrays
Initializing Array of Objects Items[] apples = new Items[3]; apples[2] = new Items(“Granny Smith”, 22); apples -> null null Lecture 16: Visualizing and Using Arrays
Initializing Array of Objects Items[] apples = new Items[3]; apples[2] = new Items(“Granny Smith”, 22); apples[0] = apples[2]; apples -> null Lecture 16: Visualizing and Using Arrays
Visualizing an Array of Objects ... apple[0].setName("McIntosh”); apple[1].setAmount(10); apples -> Lecture 16: Visualizing and Using Arrays
Swapping Elements // let’s swap apple[0] and apple[2] Items tmp = apple[0]; // Make a temporary copy. Why? apples -> tmp Lecture 16: Visualizing and Using Arrays
Swapping Elements // let’s swap apple[0] and apple[2] Items tmp = apple[0]; // Make a temporary copy. Why? apple[0] = apple[2]; apples -> tmp Lecture 16: Visualizing and Using Arrays
Swapping Elements // let’s swap apple[0] and apple[2] Items tmp = apple[0]; // Make a temporary copy. Why? apple[0] = apple[2]; apple[2] = tmp apples -> tmp Lecture 16: Visualizing and Using Arrays
Swapping Integers // swap a & b public void swap(int a, int b) { int t = a; a = b; b = t; } int a = 10; int b = 20; swap (a, b); // a = 20; b = 10; Lecture 16: Visualizing and Using Arrays
BlueJ Examples Problems • Extend Inventory class for tracking Items Lecture 16: Visualizing and Using Arrays
More Questions? Lecture 16: Visualizing and Using Arrays