CS445 Week 9: Lecture

Similar documents
Programs as Models. Procedural Paradigm. Class Methods. CS256 Computer Science I Kevin Sahr, PhD. Lecture 11: Objects

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017

CGS 2405 Advanced Programming with C++ Course Justification

Inheritance and Polymorphism

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

Chapter 7. Inheritance

JAVA MOCK TEST JAVA MOCK TEST II

Computer Sciences 302 Exam 2 Information & Sample Exam

CS-202 Introduction to Object Oriented Programming

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

Java for Non Majors. Final Study Guide. April 26, You will have an opportunity to earn 20 extra credit points.

Recommended Group Brainstorm (NO computers during this time)

Object Oriented Programming. Java-Lecture 11 Polymorphism

Programming Exercise 14: Inheritance and Polymorphism

Inheritance, and Polymorphism.

CS250 Intro to CS II. Spring CS250 - Intro to CS II 1

Lecture 36: Cloning. Last time: Today: 1. Object 2. Polymorphism and abstract methods 3. Upcasting / downcasting

Student Performance Q&A:

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

CSC207 Week 3. Larry Zhang

Chapter 6 Introduction to Defining Classes

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

Instance Members and Static Members

CS1004: Intro to CS in Java, Spring 2005

CST242 Object-Oriented Programming Page 1

CS 112 Programming 2. Lecture 10. Abstract Classes & Interfaces (1) Chapter 13 Abstract Classes and Interfaces

Announcement. Agenda 7/31/2008. Polymorphism, Dynamic Binding and Interface. The class will continue on Tuesday, 12 th August

Objects and Classes Lecture 2

CS2013 Course Syllabus Spring 2018 Lecture: Mon/Wed 2:00 P.M. 2:50 P.M. SH C259 Lab: Mon/Wed 2:50 P.M. 4:00 P.M. SH C259

MechEng SE3 Lecture 7 Domain Modelling

9/19/2018 Programming Data Structures. Polymorphism And Abstract

Inheritance and Polymorphism

COMP322 - Introduction to C++ Lecture 09 - Inheritance continued

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

Exercise: Singleton 1

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

Basic Object-Orientation

Spring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques

A Java Execution Simulator

Express Yourself. Writing Your Own Classes

Inheritance, Polymorphism, and Interfaces

CS2013 Course Syllabus Spring 2017 Lecture: Friday 8:00 A.M. 9:40 A.M. Lab: Friday 9:40 A.M. 12:00 Noon

Object Oriented Relationships

CS304 Object Oriented Programming Final Term

CS11 Introduction to C++ Fall Lecture 7

CS105 C++ Lecture 7. More on Classes, Inheritance

Exam Duration: 2hrs and 30min Software Design

CIS 120. Introduction to Programming

Objects and Iterators

Programming Languages and Techniques (CIS120)

HAS-A Relationship. If A uses B, then it is an aggregation, stating that B exists independently from A.

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Example: Count of Points

2. COURSE DESIGNATION: 3. COURSE DESCRIPTIONS:

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

Arrays Classes & Methods, Inheritance

Inheritance. Unit 8. Summary. 8.1 Inheritance. 8.2 Inheritance: example. Inheritance Overriding of methods and polymorphism The class Object

Topic 7: Algebraic Data Types

C++ Important Questions with Answers

Inheritance and Interfaces

Pieter van den Hombergh Thijs Dorssers Stefan Sobek. February 10, 2017

Pieter van den Hombergh Thijs Dorssers Stefan Sobek. January 11, 2018

Credit where Credit is Due. Lecture 4: Fundamentals of Object Technology. Goals for this Lecture. Real-World Objects

COMP322 - Introduction to C++

Computer Science II (20082) Week 1: Review and Inheritance

CS 320 Midterm Exam Solution

OVERRIDING. 7/11/2015 Budditha Hettige 82

CS32 - Week 4. Umut Oztok. Jul 15, Umut Oztok CS32 - Week 4

Topic 7: Inheritance. Reading: JBD Sections CMPS 12A Winter 2009 UCSC

CLASSES AND OBJECTS IN JAVA

Chapter 10 Classes Continued. Fundamentals of Java

Week. Lecture Topic day (including assignment/test) 1 st 1 st Introduction to Module 1 st. Practical

Data Abstraction. Hwansoo Han

Part 1: Group Brainstorm (NO computers during this time) Part 2: Submit Individual Brainstorm (You can now use a computer)

Object Oriented Software Design II

Object Oriented Software Design II

CS Operating system

Chapter 14 Abstract Classes and Interfaces

CS 170 Java Programming 1. Week 13: Classes, Testing, Debugging

Introduction to Programming System Design CSCI 455x (4 Units)

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017

CS 113 MIDTERM EXAM 2 SPRING 2013

Final Exam. Final Exam Review. Ch 1: Introduction: Object-oriented analysis, design, implementation. Exam Format

OBJECT ORIENTED PROGRAMMING. Abstract Class And Interface

CS 162, Lecture 25: Exam II Review. 30 May 2018

More About Classes CS 1025 Computer Science Fundamentals I Stephen M. Watt University of Western Ontario

EECS168 Exam 3 Review

LABORATORY 1 REVISION

Inheritance & Polymorphism Recap. Inheritance & Polymorphism 1

Java 2. Course Outcome Summary. Western Technical College. Course Information. Course History. Course Competencies

Full file at Chapter 2 - Inheritance and Exception Handling

CS/ENGRD 2110 SPRING 2018

Java Programming. U Hou Lok. Java Aug., Department of Computer Science and Information Engineering, National Taiwan University

CS 251 Intermediate Programming Inheritance

2D1358 Object Oriented Program Construction in C++ Exercises & Labs. Course Registration / Accounts. Course Literature

ITI Introduction to Computing II

Chapter 15: Object Oriented Programming

Survey #2. Programming Assignment 3. Final Exam. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu.

COMP 401 Spring 2013 Midterm 2

Transcription:

CS445 Week 9: Lecture Objectives: To discuss the solution of the midterm and answer any doubts about grading issues. Also, during the discussion, refresh the topics from the first part of the course. Reading Assignment: Textbook: pages thru 306, 320-328 (for next week). Contents: Discuss the answers of Midterm Return the graded papers and answer questions 2 hr 1 hr CS445 - Week9 Page 1 -

Discuss solution to Midterm 100 min / 100 min Return Graded Midterms and discuss individual problems 50 min / 150 min CS445 - Week9 Page 2 -

x-x-x-x-x-x-x-x-x-x--x-x-x-x-x-x-x--x-x-x-x-x-x-x-x-x-x-x-x--x-x-x-x-x-x--x-x-x- CS445 Midterm Exam Solution Question1 (10 points) Differentiate between weak and strong composition Give examples Looking for an answer in which students should give the definition of composition and explain the issue of ownership or containment. With respect to that, then give the difference between lifetime based on the ownership/containment issue. Thus defining and differentiating weak and strong composition. Not looking for code examples here, though code examples are also ok if they are explained in a proper way, i.e. plain English - stating that if the container is destroyed so will the contained in the case of strong and not in the case of weak. The answer would really be a good one if students mention the relationship in which containee gets destroyed and container can or cannot be destroyed (missile of a fighter example) that was beaten to death in class. Question2 (10 points) Discuss difference between an Abstract class and an Interface Pretty much the true java question of the exam. Looking for an answer in which there is both definitions of Abstract class and Interface. Students should have noted that none of the classes can be instantiated. However variables of abstract classes can be declared and points would not be docked for that. This question is aiming at java but students explaining on basis of c++ (i.e. interface as a header fileetc.) shall be considered for partial credit based on the answer Question3 (5 points) What is dynamic binding? If you answer this question and understand what you are saying then the next two questions are automatic. The reason is based on the understanding of this answer, your next two would depend upon. Though you can get one or the other correct, but its really the understanding that at run-time the type of the method invocation can be determined. You need to have a good understanding of polymorphism and how its implemented in memory. CS445 - Week9 Page 3 -

Question4 (15 points) There are 3 classes: Circle, Square and Triangle. Each class has the data element that contains the name of the shape (Circle, Square, Triangle). The only condition that we have for the name is that it should not be null. Based on this information, write a skeleton structure of the classes (atleast 1 constructor and accessor methods needed. Define the accessor methods based on the information given). Really looking for the use of inheritance here. If the student has answered using delegation or aggregation, points could be severely deducted as this is a straightforward question of usage of commonality or generalization. However partial credit might be given based on the performance. Though good code is expected, points shall not be cut for minor syntax errors. public class Shape private String name; public Shape ( String namein ) setname (namein) ; public String getname () return (name) ; public void setname (String namein) // some sort of error checking to see if its not null is expected // points shall be deducted for not having that name = namein; // end of class shape public class Circle extends Shape public Circle (String namein) super (namein); // end of class Circle public class Square extends Shape public Square (String namein) super (namein); // end of class Square public class Triangle extends Shape public Triangle (String namein) super (namein); // end of class Triangle Mentioning the accessors in the child classes is not necessary. If overdone, points shall not be deducted unless major mistakes occur. Another point about not overdoing. CS445 - Week9 Page 4 -

Question5 (20 points) Consider the following code public interface Flyable public void takeoff( ); // end of interface Flyable class F16 extends Fighter implements Flyable public void takeoff( ) // end of class F16 class F22 extends Fighter implements Flyable public void takeoff( ) // end of class F22 The implementation of the code is in Java. Consider the scenario in which F16 and F22 are fighters on a warship. Now the ship has multiple number of both the Fighters. The number of that aircraft can vary depending upon the other conditions based upon the extra helicopters that its carrying for the mission. Now the Ship is under enemy fire and has to get all its fighters off the board. It can do so by invoking the takeoff method of the Fighters. if (underfire) // your code Pretty much the easiest of all the questions if you know what you are doing. The only thing required here is going through a vector of Fighters and then just using the object returned to call the takeoff method on it. Again coming back to dynamic binding. Points would be deducted here for overdoing work and trying to find the type of the aircraft since its not necessary and it would add additional overhead. x-x-x-x-x-x-x-x-x-x--x-x-x-x-x-x-x--x-x-x-x-x-x-x-x-x-x-x-x--x-x-x-x-x-x--x-x-x- CS445 - Week9 Page 5 -