1 / 12

CSE115: Introduction to Computer Science I

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. Announcements. Exam 3 on Wednesday 11/11 covers material from last exam up to and including Friday 11/06 Review on Monday 11/09

faith
Download Presentation

CSE115: Introduction to Computer Science I

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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<E> • (some) classes implementing interface: • java.util.HashSet<E> • java.util.ArrayList<E> • E is the type of element contained in the collection – replace by an actual type

  8. Use of a collection HashSet<String> names = new HashSet<String>(); 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<E> myCollection; myCollection = new ArrayList<E>(); myCollection = new HashSet<E>();

  11. Polymorphism and Collections(polymorphic dispatch, just like we saw on Friday) Collection<ITool> 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<E>) 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.

More Related