CSSE221: Software Dev. Honors Day 10 Announcements Announcements Fifteen due Monday 11:59 pm. Monday will be a workday. Fifteen due Monday 11:59 pm. Monday.

Slides:



Advertisements
Similar presentations
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 21: Strings (cont.)
Advertisements

Generics. DCS – SWC 2 Generics In many situations, we want a certain functionality to work for a variety of types Typical example: we want to be able.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 Chapter 12 More OOP, Interfaces, and Inner Classes.
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
Slides prepared by Rose Williams, Binghamton University Chapter 14 Generics and the ArrayList Class.
CSSE221: Software Dev. Honors Day 6 Announcements Announcements Questions? Questions? Hint on BallWorlds’ changing the x and y coords in 2 nd half of lecture.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Software Development Software Life Cycle UML Diagrams.
CSSE221: Software Dev. Honors Day 16 Announcements Announcements Markov due Wednesday 11:59 pm Markov due Wednesday 11:59 pm Homework 6 due next Tuesday,
CSSE221: Software Dev. Honors Day 4 Pass in Runtime Assignment now to assistants Pass in Runtime Assignment now to assistants Announcements Announcements.
CSSE221: Software Dev. Honors Day 25 Announcements: Announcements: Now returning programming mini-exam feedback, HW7, and some capsule quizzes. Now returning.
CSSE221: Software Dev. Honors Day 2 Announcements Announcements Homework due now Homework due now Any problems committing JavaEyes to Subversion? Any problems.
CSSE221: Software Dev. Honors Day 8 Announcements Announcements HW3 due now, solutions will be posted. HW3 due now, solutions will be posted. Questions.
CSSE221: Software Dev. Honors Day 5 Announcements Announcements Homework 2 written portion due now Homework 2 written portion due now You survived the.
CSSE221: Software Dev. Honors Day 13 Announcements Announcements Contractions throughout the night… Contractions throughout the night… Late day assignments.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
CSSE221: Software Dev. Honors Day 28 Announcements Announcements Simulation grades coming back Simulation grades coming back All C Projects due Friday.
CSSE221: Software Dev. Honors Day 7 Announcements Announcements HW2 and inheritance quiz returned now. HW2 and inheritance quiz returned now. Solutions.
Slides prepared by Rose Williams, Binghamton University Chapter 14 Generics and the ArrayList Class.
CSSE221: Software Dev. Honors Day 11 Pass in HW4 now Pass in HW4 now Fifteen due 11:59pm Fifteen due 11:59pm Announcements Announcements Questions on Fifteen?
CSSE221: Software Dev. Honors Day 9 Announcements Announcements HW3 passed back, follow link from HW3 to its solution. HW3 passed back, follow link from.
CSE 115 Week 3 January 28 – February 1, Monday Announcements Software Installation Fest: 2/5 and 2/6 4pm – 7pm in Baldy 21 Software Installation.
Templates. Objectives At the conclusion of this lesson, students should be able to Explain how function templates are used Correctly create a function.
CSSE221: Software Dev. Honors Day 17 Announcements Announcements Fifteen and CarsTrucksTrains coming back Fifteen and CarsTrucksTrains coming back Note:
Java Implementation Software Construction Lecture 6.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Lecture 7 Polymorphism. Review: Constructors ●Parenthesis after constructor, not in class declaration ●The constructor makes the SamBot – do not “ new.
SE 350 – Programming Games Lecture 6: Programming with Unity Lecturer: Gazihan Alankuş Please look at the last slide for assignments (marked with TODO)
Lecture 22 Miscellaneous Topics 4 + Memory Allocation.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
Principles of Computer Science I Honors Section Note Set 1 CSE 1341 – H 1.
240-Current Research Easily Extensible Systems, Octave, Input Formats, SOA.
1 FUNCTIONS - I Chapter 5 Functions help us write more complex programs.
CS2210: SW Development Methods Topics: Comparable and Comparator interfaces in JCF Function objects Textbook readings: More from MSD, Chapter 9 Pages
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming – Home and reload buttons for the webbrowser, Applets.
Lecture 121 CS110 Lecture 12 Tuesday, March 9, 2004 Announcements –hw5 due Thursday –Spring break next week Agenda –questions –ArrayList –TreeMap.
Introduction to Methods Shirley Moore CS 1401 Spring 2013 cs1401spring2013.pbworks.com April 1, 2013.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming –TextField Action Listeners, JEditorPane action listeners, HTML in a JEditorPane,
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Thomas Kuehne.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
Generic Programming and Inner classes ge·ner·ic 1a : relating or applied to or descriptive of all members of a genus, species, class, or group : common.
Object Oriented Programming Criteria: P2 Date: 07/10/15 Name: Thomas Jazwinski.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
Chapter 4: More Object Concepts. Objectives Understand blocks and scope Overload a method Avoid ambiguity Create and call constructors with parameters.
Swing Threading Nested Classes COMP 401 Fall 2014 Lecture 23 11/25/2014.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
Arrays Chap. 9 Storing Collections of Values 1. Introductory Example Problem: Teachers need to be able to compute a variety of grading statistics for.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
Inner Classes.
Topic: Inner Classes Course : JAVA PROGRAMMING Paper Code: ETCS-307 Faculty : Dr. Prabhjot Kaur Reader, Dept. of IT 1.
Intro CS – Screens and Variables
Java Programming: Guided Learning with Early Objects
CMPE212 – Stuff… Assn 3 due and Quiz 2 in the lab next week.
PC02 Term 1 Project Basic Messenger. PC02 Term 1 Project Basic Messenger.
Workshop for Programming And Systems Management Teachers
CISC124 Assignment 3 sample solution will be posted tonight after 7pm.
Week 4 Lecture-2 Chapter 6 (Methods).
Inner Classes 17-Apr-19.
Inner Classes 21-Apr-19.
Inner Classes 11-May-19.
Inner Classes 18-May-19.
Inner Classes 25-Oct-19.
Presentation transcript:

CSSE221: Software Dev. Honors Day 10 Announcements Announcements Fifteen due Monday 11:59 pm. Monday will be a workday. Fifteen due Monday 11:59 pm. Monday will be a workday. Quizzes passed back Quizzes passed back Sec 2, question 8. Are all events handled by some sort of listener? Sec 2, question 8. Are all events handled by some sort of listener? Questions on GUIs, EventListeners or Fifteen? Questions on GUIs, EventListeners or Fifteen? Fire up Angel and Eclipse now Fire up Angel and Eclipse now

This week: Fifteen assignment Monday: Monday: GUIs using Java’s Swing library GUIs using Java’s Swing library Tuesday: Tuesday: Fifteen specification Fifteen specification EventListeners: responding to user input EventListeners: responding to user input Intro to UML as a design tool Intro to UML as a design tool Time to work on project Time to work on project Thursday: Thursday: Start prep for round 2 capsules Start prep for round 2 capsules Anonymous classes (capsule) Anonymous classes (capsule) Function objects and comparators (capsule) Function objects and comparators (capsule)

How to do a capsule? Round 2: +Demo and Activity I still lecture (15-20 min). I still lecture (15-20 min). You still create a summary and quiz. You still create a summary and quiz. Now, you create the demonstration. Now, you create the demonstration. Code that shows a concept. Code that shows a concept. How will you know if your classmates are understanding it? How will you know if your classmates are understanding it? Now, you create a hands-on activity for the class, like? Now, you create a hands-on activity for the class, like? Start the demo code together (like SwingDemo) Start the demo code together (like SwingDemo) Have them extend the demo code (like SalariedEmployee) Have them extend the demo code (like SalariedEmployee) Do a kinesthetic activity (like having the class act out a sort method) Do a kinesthetic activity (like having the class act out a sort method) Use your creativity! Use your creativity!

More about the Demo/Activity Total time for both: ~25-30 minutes Total time for both: ~25-30 minutes Integrate your quiz with your demo/activity: Integrate your quiz with your demo/activity: 2-3 questions must relate to them. 2-3 questions must relate to them. Roles of Teammates: Roles of Teammates: 1. Demo Driver: explains the code and adds any live code 2. Roving Expert: checks if any students are having difficulties, asks if they need help 3. Questioner: chooses students to ask the questions on the quiz, asks them, and provides encouragement or corrective feedback as appropriate.

Capsule Deliverables By 7:30 am on the day you are presenting: By 7:30 am on the day you are presenting: the quiz, key, and summary to me (as before) the quiz, key, and summary to me (as before) Commit your demo to csse public Commit your demo to csse public Include your section number in the project name: csse221 Include your section number in the project name: csse221 Bring to class printed versions (as before): Bring to class printed versions (as before): 1 copy of summary 1 copy of summary 2 copies of key 2 copies of key Enough copies of quiz for the class (20) Enough copies of quiz for the class (20)

Choose topic preferences for group 2 Angel survey in Lessons > Other Angel survey in Lessons > Other 2 minutes 2 minutes

Anonymous Classes Say I have a really small class that won’t get re- used by other classes. Say I have a really small class that won’t get re- used by other classes. If I don’t want to write it in its own file, I have 3 options: If I don’t want to write it in its own file, I have 3 options: Nested classes Nested classes Local classes Local classes Anonymous classes Anonymous classes

Nested Classes A class defined within another class. It is only visible to the outer class. A class defined within another class. It is only visible to the outer class. It must be declared static, or else it is an inner class. Inner classes are typically made visible to the world (like Ellipse2D.Double) It must be declared static, or else it is an inner class. Inner classes are typically made visible to the world (like Ellipse2D.Double)

Local Classes Declared inside a method Declared inside a method Their scope is only the method in which they are declared Their scope is only the method in which they are declared Not declared private or static. Not declared private or static. Have access to local final variables of the method. Have access to local final variables of the method. Weiss doesn’t use these Weiss doesn’t use these

Anonymous Inner Classes A class with no name! A class with no name! So it can only be used once! So it can only be used once! Used to provide a class that implements an interface (or extends a class). Used to provide a class that implements an interface (or extends a class). Instead of writing new Inner(), we write new Interface(), then provide the definition of the interface’s methods in curly braces {}. Instead of writing new Inner(), we write new Interface(), then provide the definition of the interface’s methods in curly braces {}. To extend a class, we provide definitions of the overridden methods To extend a class, we provide definitions of the overridden methods Limitation: can’t specify a constructor Limitation: can’t specify a constructor

Demo Check out SwingDemoWithAnonymousClasses Check out SwingDemoWithAnonymousClasses Disconnect Disconnect Together, we’ll make the listeners anonymous Together, we’ll make the listeners anonymous Then, 5-minute break Then, 5-minute break

Function Objects (a.k.a. Functors) Consider sorting an array of objects. Consider sorting an array of objects. Sorting requires elements can be comparable, such as numbers. Sorting requires elements can be comparable, such as numbers. However, what if there were more than one way to compare the elements? However, what if there were more than one way to compare the elements? We’d like to be able to tell the sorting function how to compare the elements. We’d like to be able to tell the sorting function how to compare the elements.

Function Objects (a.k.a. Functors) We'd like to be able to pass a method as an argument to another method. (what is the role of arguments to methods in general?) We'd like to be able to pass a method as an argument to another method. (what is the role of arguments to methods in general?) This is not a new or unusual idea. This is not a new or unusual idea. We frequently pass other functions as arguments to Maple's plot and solve functions. We frequently pass other functions as arguments to Maple's plot and solve functions.

Function Objects (a.k.a. Functors) We'd like to be able to pass a method as an argument to another method. We'd like to be able to pass a method as an argument to another method. This is not a new or unusual idea. This is not a new or unusual idea. Maple's plot and solve can take function arguments. Maple's plot and solve can take function arguments. C and C++ provide qsort, whose first argument is a comparison function. C and C++ provide qsort, whose first argument is a comparison function. Scheme has sort, which can take a function as its first argument. Scheme has sort, which can take a function as its first argument.

Function Objects What's it all about? What's it all about? Unfortunately, Java (unlike C++) doesn't allow functions to be passed directly as arguments. Unfortunately, Java (unlike C++) doesn't allow functions to be passed directly as arguments. But we can create objects whose only purpose is to pass a function into a method. They are called function objects, a.k.a. functors. But we can create objects whose only purpose is to pass a function into a method. They are called function objects, a.k.a. functors. Weiss' example: Weiss' example: Uses Comparator objects (interface is defined in java.util.Comparator ). Uses Comparator objects (interface is defined in java.util.Comparator ). What is Comparator used for? What is Comparator used for? Why not just use Comparable? Why not just use Comparable? OrderRectByWidth, SimpleRect, CompareTest OrderRectByWidth, SimpleRect, CompareTest

How to pronounce Comparator, Comparable

Comparator Interface Weiss provides code for several classes that are equivalent to those in java.util, so we can see how parts of the java.util classes might be implemented. You can install this  Generics would make this code more complicated; we’ll deal with that later.

Comparator Example part 1 The SimpleRectangle class does not implement Comparable, because there is no one "natural" way to order SimpleRectangle objects.

Comparator Example part 2 Two comparator classes.

Comparator Example part 3 Without something like Comparators, we would need separate findMax functions for finding the max using different comparison criteria  Note that java.util.Collections.max() has similar functionality for ArrayLists and other collections.

Demo Passing a comparator to a sort method. Passing a comparator to a sort method. Check out the ComparatorDemo project. Check out the ComparatorDemo project. Follow the directions on the top of the program. Follow the directions on the top of the program.

On HW5… Weiss (was in ed. 2) Weiss (was in ed. 2) Read over now Read over now EqualsK should implement your interface from the first problem. Add extra tests to your main method to create some different equalsK objects and pass them, along with an interesting array, to the countMatches() method. EqualsK should implement your interface from the first problem. Add extra tests to your main method to create some different equalsK objects and pass them, along with an interesting array, to the countMatches() method. You can submit (to the drop box for WA2) one set of classes that solves and tests both problems. You can submit (to the drop box for WA2) one set of classes that solves and tests both problems.

Hints Analogy with the Rectangle example: Analogy with the Rectangle example: countMatches (like findMax) is the method that takes an array and a function object as parameters. countMatches (like findMax) is the method that takes an array and a function object as parameters. EqualsZero (like findMaxByWidth) is specific function object. EqualsZero (like findMaxByWidth) is specific function object. ??? (like Comparator) is the function object interface: you pick the name. ??? (like Comparator) is the function object interface: you pick the name.