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 Lab 6 overview and tips Collections Inheritance – our last relationship!

4 Lab 6 tips and notes Eclipse –//TODO comments –Tasks view Java –Implicit constructors –System.out.println General –work systematically and incrementally

5 Lab 6 class diagram State pattern shown on board Polymorphic dispatch is selection based on type –foreshadowing upcoming slides: no if- else or similar statements are needed (or allowed) in lab 6.

6 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?

7 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

8 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”); …

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

10 Polymorphism and Collections (always code to interface) Collection myCollection; myCollection = new ArrayList (); myCollection = new HashSet ();

11 Polymorphism and Collections (polymorphic dispatch, just like we saw on Friday) Collection toolBox; toolBox = new...;... toolBox.add(new CircleTool()); toolBox.add(new SquareTool()); toolBox.add(new NullTool());... java.awt.Point p =...; for (ITool tool : toolBox) { tool.apply(p); }

12 Collections.shuffle (a useful method to know) Collections.shuffle(List ) This method rearranges the elements in the list passed as an argument, in a random order. Note that the collection passed in must be a List, not a general collection, because the collection must support order operations.


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