Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.

Slides:



Advertisements
Similar presentations
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
Advertisements

METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
Written by: Dr. JJ Shepherd
Intro to OOP with Java, C. Thomas Wu Inheritance and Polymorphism
SE-1020 Dr. Mark L. Hornick 1 Inheritance and Polymorphism: Abstract Classes The “not quite” classes.
Lecture 17 Abstract classes Interfaces The Comparable interface Event listeners All in chapter 10: please read it.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
CS180 Review Questions. Administriva Final Exam –Friday 8am MTHW 210 –No GUI programming question –Format 35 multiple choice questions 4 programming.
Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.
Part-B1 Stacks. Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations.
Cmp Sci 187: Midterm Review Based on Lecture Notes.
1 Topic 10 Abstract Classes “I prefer Agassiz in the abstract, rather than in the concrete.”
Building Java Programs Inner classes, generics, abstract classes reading: 9.6, 15.4,
Chapter 10 Classes Continued
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
OOP Languages: Java vs C++
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Multiple Choice Solutions True/False a c b e d   T F.
Classes and objects Practice 2. Basic terms  Classifier is an element of the model, which specifies some general features for a set of objects. Features.
Unit 5 School of Information Systems & Technology1 School of Information Systems and Technology (IST)
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Java Classes, Interfaces, and Types 1.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
1 Review of Java Higher Level Language Concepts –Names and Reserved Words –Expressions and Precedence of Operators –Flow of Control – Selection –Flow of.
Introduction to Java Prepared by: Ahmed Hefny. Outline Classes Access Levels Member Initialization Inheritance and Polymorphism Interfaces Inner Classes.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 9 - Inheritance.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
CSC 205 Java Programming II Polymorphism. Topics Polymorphism The principle of substitution Dynamic binding Object type casting Abstract class The canonical.
© 2004 Goodrich, Tamassia Stacks. © 2004 Goodrich, Tamassia Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data.
Inheritance (Part 4) Abstract Classes 1.  sometimes you will find that you want the API for a base class to have a method that the base class cannot.
Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Inheritance and Polymorphism.
1 Abstract Classes “I prefer Agassiz in the abstract, rather than in the concrete.” CS Computer Science II.
1/20/03A2-1 CS494 Interfaces and Collection in Java.
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John.
CSE 143 Lecture 24 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, , slides.
Object-Oriented Programming © 2013 Goodrich, Tamassia, Goldwasser1Object-Oriented Programming.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Recitation 5 Enums and The Java Collections classes/interfaces 1.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 11 Inheritance and Polymorphism.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
More Java: Static and Final, Abstract Class and Interface, Exceptions, Collections Framework 1 CS300.
Inheritance and Subclasses CS 21a. 6/28/2004 Copyright 2004, by the authors of these slides, and Ateneo de Manila University. All rights reserved L16:
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Programming in java Packages Access Protection Importing packages Java program structure Interfaces Why interface Defining interface Accessing impln thru.
Introduction to Collections. Collections Collections provide a way of organizing related data in a model Different types of collections have different.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Design Patterns. Outline Purpose Purpose Useful Definitions Useful Definitions Pattern Overview Pattern Overview.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
(c) University of Washington05-1 CSC 143 Java Abstract Classes and Frameworks Reading: Ch. 11.
Further Abstraction Techniques Chapter 10. Abstract Classes There are times when you do not want someone to be able to make an object of your class. For.
This In Java, the keyword this allows an object to refer to itself. Or, in other words, this refers to the current object – the object whose method or.
Chapter 9: Continuing Classes By Matt Hirsch. Table Of Contents 1.Static Fields and Methods 2.Inheritance I. Recycle Code with Inheritance II. Overriding.
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
9.1 CLASS (STATIC) VARIABLES AND METHODS Defining classes is only one aspect of object-oriented programming. The real power of object-oriented programming.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
Inheritance and Polymorphism
Chapter 11: Inheritance and Polymorphism
Agenda Warmup AP Exam Review: Litvin A2
Java Programming: Guided Learning with Early Objects
Topic 10 Abstract Classes “I prefer Agassiz in the abstract,
Topic 10 Abstract Classes “I prefer Agassiz in the abstract,
Chapter 9 Carrano Chapter 10 Small Java
Chapter 14 Abstract Classes and Interfaces
CS 112 Programming 2 Lecture 02 Abstract Classes & Interfaces (2)
Presentation transcript:

Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the question, then the answer, and go “Okay, that makes sense” (as opposed to actively attempting to think about a solution first).

Choose a category. You will be given the answer. You must give the correct question. Click to begin.

Click here for Final Jeopardy

Data Structures Jolly Java Crafty Coding 10 Point 20 Points 30 Points 40 Points 50 Points 10 Point 20 Points 30 Points 40 Points 50 Points 30 Points 40 Points 50 Points Typing & Hierarchy Ominous OCaml

Write in Java: let x: int ref = ref 1

int x = 1;

Write in Java: let y (x: int): int = x * x + 1

int y(int x) { return x * x + 1; }

Write in Java: type node = { val : int; mutable next : node option } let make_node (v:int) (n:node option) : node = { val = v; next = n}

class Node { private final int val; public int getVal() { return val; } public Node next; public Node(int v, Node n){ val = v; next = n; } }

Write in Java: type cs = { mutable cnt : int } let new_counter (): (unit -> unit * unit -> int) = let x: cs = { cnt = 0 } in (fun () -> x.cnt x.cnt)

public class Counter { private int cnt; public Counter() { cnt = 0; } public void increment() { cnt++; } public int get() { return cnt; } }

Write in Java: type Shape = Point of int * int | Line of int * int * int *int let draw (s:Shape) (gc: Graphics.t) = begin match s with Point (x,y) -> gc.drawPoint(x,y) | Line (x1,y1,x2,y2) -> gc.drawLine(x1,y1,x2,y2) end

interface Shape { public void draw(Graphics gc); } class Point implements Shape { int x; int y; public void draw(Graphics gc) { gc.drawPoint(x,y); } } class Line implements Shape { int x1; int y1; int x2; int y2; public void draw(Graphics gc) { gc.drawLine(x1,y1,x2,y2); } }

Give an example of data that can be modeled as ('a, 'b set) map

A classroom of students, each with a set of grades.

Give an example of data that can be modeled as List >

A bookshelf of phone books.

What is the main difference between OCaml and Java data structures?

Mutability.

What is one implementation strategy for the finite map ADT?

A set of key-value pairs, or a BST with no repeated elements and a key for each element.

What are two implementation strategies for the set ADT?

A list with no repeats, a BST with no repeats, or a map with dummy keys.

What are the static type and dynamic class of x in the following? Iterator x = new Scanner();

Static type: Iterator Dynamic type: Scanner

Name two major differences between interfaces and classes.

1. A class can extend one class but interfaces may extend many interfaces. 2. An interface cannot contain implementation code; a class can.

What is dynamic dispatch? How does it work in the abstract machine model?

Dynamic dispatch: what code (e.g. method body) is executed depends on the dynamic class of the object. The dynamic class is stored in the heap as part of the object. Methods are stored in the class table, if the method is not in the object’s class, then the ASM looks in the superclasses.

List l = new LinkedList (); l.add(new A()); l.add(new B()); D d = l.get(0); Draw an inheritance tree for classes A, B, C, and D.

D C B A

List i = new ArrayList (); ArrayList j = new ArrayList (); List k; For each assignment, state whether valid. Assume they run independently. i = j; j = i; k = i; k = j;

i = j; // Okay j = i; // Bad k = i; // Bad k = j; // Bad

What is the superclass of all classes?

Object

What is overriding?

Overriding: redefining a method in a subclass (the redefined method must have the same type).

Describe a situation where you might define an inner class?

If you need two classes to share private state. For example, an event listener in a GUI needs to update the state of the application.

What is the value of x after executing the following code: int x = 0; try { x = 3; throw new IOExecption(); } catch (Exception e) { x = 4; }

4

Name two different uses of the static keyword in Java; explain the effect on each kind of entity.

Methods: static methods belong to the class, and can be invoked without instances of the class e.g. Math.cos(80); Variables: static variables belong to the class, and are shared by all instances.

Complete the method: // Returns twice the number if odd, // else the number if even. int foo(int x);

int foo(int x) { if (x % 2 == 0) // even return x; else return x * 2; }

Design classes/interfaces for the situation: You are writing a Blackboard-alternative software for a class. The software has a dropbox for students to submit assignments (each assignment is either a text document, a code ZIP, or an image diagram). Assignments are identified by a numerical ID. The professor wants to be able to: - access all documents submitted for a given assignment, in the order they were submitted - assign a grade to each assignment

Sample, this has no fixed solution! interface Assignment { int getGrade(); void assignGrade(int x); File getFile(); } class Text extends Assignment … class Code extends Assignment… class Diagram extends Assignment… class DropBox { List getFilesForAssignment(int assignment_id); }

Complete the method: // Returns the number, // or 0 if not a numerical string. // You should use Integer.parseInt int getIntFrom(String s);

int getIntFrom(String s) { int x = 0; try { x = Integer.parseInt(s); } catch (NumberFormatEx..) { // Leave x = 0. } return 0; }

Complete the method: // Recursive method that returns // true if string is palindrome. boolean isPalindrome(String s);

boolean isPalindrome(String s) { if (s.length() <= 1) return true; if (s.charAt(0) == s.charAt(s.length()-1)) { String tmp = s.substring(1, s.length()-1); return isPalindrome(tmp); } else { return false; } }

Complete the method: // Reverse array in place. void reverseArray(Object[] o);

void reverseArray(Object[] o) { for (int i = 0; i < o.length/2; i++) { Object tmp = o[i]; o[i] = o[o.length-i-1]; o[o.length-i-1] = tmp; } }

Make your wager

What are the four steps of the design process to translate informal specifications into code?

1. Understand the problem. 2. Formalize the interface. 3. Write test cases. 4. Implement required behavior.