Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:50 645-4739

Similar presentations


Presentation on theme: "CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:50 645-4739"— Presentation transcript:

1 CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:50 645-4739 alphonce@buffalo.edu

2 Announcements Exam 3 on Wednesday 11/11 –covers material from last exam up to and including Friday 11/06 Review on Monday 11/09 Exercises: FA09-CSE115-Exercises project in LectureCode repository Review session – stay tuned for announcement!

3 Agenda If you started lab early… Collections Inheritance – our last relationship!

4 Collections We have seen that a variable can hold one object reference at a time. How do we effectively deal with multiple references? –arbitrarily many –what does addActionListener do?

5 Collections interface: java.util.Collection (some) classes implementing interface: –java.util.HashSet –java.util.ArrayList E is the type of element contained in the collection – replace by an actual type

6 Use of a collection HashSet names = new HashSet (); names.add(“Amy”);names.remove(“Bob”); names.add(“Bob”); names.add(“Cindy”); names.add(“Dave”); names.add(“Emma”); …

7 for-each loop for (String name : names) { System.out.println(name); } This would print out: Amy Cindy Dave Emma

8 Code demo We looked at using a collection to print out information about different types of TAs. This is clearly a toy example. We used this to illustrate the use of a collection, the foreach loop, and String concatenation.

9 package pkg; public class UTA implements TA { private String _name; public UTA(String name) { _name = name; } public String job() { return "teach recitations"; } public String name() { return _name; } UTA code (see “CollectionExample” project in LectureCode repository)

10 GTA code (see “CollectionExample” project in LectureCode repository) package pkg; public class GTA implements TA { private String _name; public GTA(String name) { _name = name; } public String job() { return "grade labs"; } public String name() { return _name; }

11 String concatenation ‘+’ is the String concatenation operator If s1 and s2 are references to String objects, then s1+s2 is an expression whose value is a reference to a new String object, consisting of all the characters of s1, followed by all the characters of s2.


Download ppt "CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:50 645-4739"

Similar presentations


Ads by Google