Department of Civil and Environmental Engineering, Spring Semester, ENCE 688R: Midterm Exam: 1 1/2 Hours, Open Book and Open Notes

Size: px
Start display at page:

Download "Department of Civil and Environmental Engineering, Spring Semester, ENCE 688R: Midterm Exam: 1 1/2 Hours, Open Book and Open Notes"

Transcription

1 Department of Civil and Environmental Engineering, Spring Semester, 2012 ENCE 688R: Midterm Exam: 1 1/2 Hours, Open Book and Open Notes Name : Question Points Score Total 80 1

2 Question 1: 30 points This question is about Java s mechanisms for programming by extension. We begin with the class Circle, which defines circles by their radius and (x,y) co-ordinates of the center, and then develop a second class, ColoredCircle, for Colored cirles. The details of class Circle are as follows: source code /* * ================================================================= * Circle(): This class defines circles. * ================================================================= */ import java.lang.math.*; public class Circle { double dx, dy, dradius; // Constructor public Circle() { public Circle( double dx, double dy, double dradius ) { this.dx = dx; this.dy = dy; this.dradius = dradius; // Compute the circle area... public double Area() { return Math.PI*dRadius*dRadius; // Copy circle parameters to a string format... public String tostring() { return "(x,y) = (" + dx + "," + dy + "): Radius = " + dradius; // Exercise methods in class Circle... public static void main( String [] args ) { System.out.println("Exercise methods in class Circle"); System.out.println("================================"); Circle ca = new Circle( 1.0, 2.0, 3.0 ); System.out.println("Circle ca : " + ca.tostring() ); System.out.println("Circle ca : Area = " + ca.area() ); 2

3 And the details of class ColoredCircle are as follows: source code /* * ================================================================= * coloredcircle(): This class defines colored circles. * ================================================================= */ import java.awt.color; public class ColoredCircle extends Circle { private Color color; // Constructor methods public ColoredCircle() { super(); this.color = Color.red; public ColoredCircle( double dx, double dy, double dradius, Color color ) { super(); this.dx = dx; this.dy = dy; this.dradius = dradius; this.color = color; // Retrieve colors... public String getcolors() { return "Color (r,g,b) = (" + color.getred() + "," + color.getgreen() + "," + color.getblue() + ")"; // =============================================== // Exercise methods in class ColoredCircle()... // =============================================== public static void main( String [] args ) { System.out.println("Exercise methods in class ColoredCircle"); System.out.println("======================================="); // Create, initialize, and print circle "ca"... ColoredCircle ca = new ColoredCircle( 1.0, 2.0, 3.0, Color.blue ); ca.dx = 1.0; 3

4 ca.dy = 2.0; ca.dradius = 3.0; ca.color = Color.blue; System.out.println( "Circle ca:" + ca.tostring() ); System.out.println( ca.getcolors() ); // Create, initialize, and print circle "cb"... ColoredCircle cb = new ColoredCircle( 1.0, 2.0, 3.0, Color.orange ); System.out.println( "Circle cb:" + cb.tostring() ); System.out.println( cb.getcolors() ); The program input/output generated by main() in Circle is: prompt >> java Circle Exercise methods in class Circle ================================ Circle ca : (x,y) = (1.0,2.0): Radius = 3.0 Circle ca : Area = prompt >> And the program output generated by main() in ColoredCircle is: prompt >> java ColoredCircle Exercise methods in class ColoredCircle ======================================= (x,y) = (1.0,2.0): Radius = 3.0 Color (r,g,b) = (0,0,255) (x,y) = (1.0,2.0): Radius = 3.0 Color (r,g,b) = (255,200,0) prompt >> Please examine the source code carefully and answer the following questions. [1a] (2 pts). Draw and label a schematic showing the relationship between the classes Circle and ColoredCircle. 4

5 [1b] (3 pts). List the variables and methods contained within the class Circle. [1c] (2 pts). What is the purpose of the line import java.lang.math.*; in Circle.java? And why is it needed by this program? [1d] (3 pts). Suppose that the line: Circle ca = new Circle( 1.0, 2.0, 3.0 ); in method main() of Circle is replaced by: Circle ca = new Circle( ); How would you modify the source code so that the overall functionality of main() remains unchanged? 5

6 [1e] (3 pts). How would you modify Circle.java so that the circle area is printed to three decimal places of accuracy (i.e., Circle ca: Area = ). [1f] (3 pts). List the variables and methods defined in the source code for ColoredCircle [1g] (3 pts). List the variables and methods available to ColoredCircle via inheritance mechanisms from Circle 6

7 [1h] (3 pts). What is the purpose of each term in: public class ColoredCircle extends Circle { [1i] (2 pts). What is the purpose of the method call super() in public ColoredCircle() { super(); this.color = Color.red; Suppose that Circle.java and ColoredCircle.java are located in the same directory (with no other files present). [1j] (3 pts). List the files that will exist in the directory before and after the compilation command: prompt >> javac Circle.java [1k] (3 pts). Now suppose that all of the bytecode files in part 1j are deleted. List the files that will exist in the directory before and after the compilation command: prompt >> javac ColoredCircle.java 7

8 Question 2: 50 points Let s suppose that we wish to model and visualize the house and grounds scene shown in Figure 1. Since there are many items to model and visualize, use of the Java Collections Framework makes sense. A second potentially good idea is to model the scene as a collection of features, with the trees, gate, house, pathway, island, and rail perimeter all being features in the house and grounds scene. Figure 2 shows a tentative class hierarchy for the modeling of features, geometric features and topological features. All features will have a name. Some features will also have geometry the latter is needed for visualization of the scene. Topological features are important for capturing notions of connectivity, thereby allowing for questions of the type: How do I get from the gate to the island? to be answered. Now let s suppose that you are in the very early stages of the model development, with everything being ignored except the small group of trees adjacent to the house. You are experimenting with the following set of source code files: build.xml, Feature.java, AbstractFeature.java, Location.java, TestScene.java and Tree.java. Details of the java source code files are as follows: File: Feature.java source code /* * =================================================================== * Feature.java: Geographic feature interface... * =================================================================== */ package scene; public interface Feature { public void setname( String sname ); public String getname(); public void setx( double dx ); public double getx(); public void sety( double dy ); public double gety(); File: AbstractFeature.java source code /* 8

9 Figure 1: Modeling for a house and its surrounding grounds. Scene 1..n << interface >> Feature << abstract >> << abstract >> AbstractGeometry AbstractTopology 1 Chain 1 Point 1 Node 2 i Link m Line 1 Coord 1 Figure 2: Conceptual model for a scene assembled from features. 9

10 * =================================================================== * AbstractFeature.java: Abstract class for geographic features... * =================================================================== */ package scene; public abstract class AbstractFeature implements Feature { protected Location c = new Location(); protected String sname; public AbstractFeature () { public AbstractFeature ( double dx, double dy ) { c.dx = dx; c.dy = dy; public void setname( String sname ) { this.sname = sname; public String getname() { return sname; public void setx( double dx ) { c.dx = dx; public double getx() { return c.dx; public void sety( double dy ) { c.dy = dy; public double gety() { return c.dy; File: Location.java source code /* * ============================================================ * Location.java: Store (x,y) location of a geographic feature. * ============================================================ 10

11 */ package scene; public class Location { double dx, dy; File: Tree.java source code /* * =================================================================== * Tree.java: Create a tree... * =================================================================== */ package scene.primitive; import scene.*; public class Tree extends AbstractFeature { public Tree() { public Tree ( double dx, double dy ) { super ( dx, dy ); public String tostring() { String s = "Tree: Name = " + sname + "\n"; s = s + " " + "Location (x,y) = (" + getx() + "," + gety() + ")"; return s; File: TestScene.java source code /* * ======================================================================= * TestScene.java: Create collections of simple geographic features. * ======================================================================= 11

12 */ package demo; import java.util.*; import scene.*; import scene.primitive.*; public class TestScene { public static void main(string[] args) { // Part 01: Create three tree objects... Tree tree01 = new Tree( 1.0, 1.0 ); tree01.setname("big Fur"); Tree tree02 = new Tree( 3.0, 2.0 ); tree02.setname("weeping Willow"); Tree tree03 = new Tree( 3.0, 5.0 ); tree03.setname("canadian Maple"); System.out.println("Part 01: Print details of tree objects" ); System.out.println("======================================" ); System.out.println( tree01 ); System.out.println( tree02 ); System.out.println( tree03 ); // Part 02: Create an arraylist of geographic features... ArrayList<Feature> array = new ArrayList<Feature>(); array.add( tree01 ); array.add( tree02 ); array.add( tree03 ); // Create duplicate entry... array.add( tree03 ); System.out.println("Part 02: Arraylist of trees" ); System.out.println("===========================" ); System.out.println( array ); // Part 03: Create and print a hashset of geographic features... Set<Feature> set = new HashSet<Feature>(); set.add (tree01); set.add (tree02); set.add (tree03); // Create duplicate entry... set.add (tree03); 12

13 System.out.println("Part 03: HashSet of trees" ); System.out.println("=========================" ); System.out.println( set ); // Part 04: Create and populate the hashmap of geographic features... Map<String, Feature> map = new HashMap<String, Feature>(); map.put ( tree01.getname(), tree01 ); map.put ( tree02.getname(), tree02 ); map.put ( tree03.getname(), tree03 ); // Create duplicate entry... map.put ( tree03.getname(), tree03 ); System.out.println("Part 04: HashMap of trees" ); System.out.println("=========================" ); System.out.println( map ); // Part 05: Assemble a treemap from the hashmap... Map treemap = new TreeMap ( map ); System.out.println("Part 05: TreeMap of trees" ); System.out.println("=========================" ); System.out.println( treemap ); The script of program input and output is as follows: prompt >> ant run01 Buildfile: /Users/austin/ence688r.d/exam-code.d/build.xml compile: [javac] /Users/austin/ence688r.d/exam-code.d/build.xml:9: run01: [java] Part 01: Print details of tree objects [java] ====================================== [java] Tree: Name = Big Fur [java] Location (x,y) = (1.0,1.0) [java] Tree: Name = Weeping Willow [java] Location (x,y) = (3.0,2.0) [java] Tree: Name = Canadian Maple [java] Location (x,y) = (3.0,5.0) [java] Part 02: Arraylist of trees [java] =========================== 13

14 [java] [Tree: Name = Big Fur [java] Location (x,y) = (1.0,1.0), Tree: Name = Weeping Willow [java] Location (x,y) = (3.0,2.0), Tree: Name = Canadian Maple [java] Location (x,y) = (3.0,5.0), Tree: Name = Canadian Maple [java] Location (x,y) = (3.0,5.0)] [java] Part 03: HashSet of trees [java] ========================= [java] [Tree: Name = Canadian Maple [java] Location (x,y) = (3.0,5.0), Tree: Name = Weeping Willow [java] Location (x,y) = (3.0,2.0), Tree: Name = Big Fur [java] Location (x,y) = (1.0,1.0)] [java] Part 04: HashMap of trees [java] ========================= [java] {Weeping Willow=Tree: Name = Weeping Willow [java] Location (x,y) = (3.0,2.0), Canadian Maple=Tree: Name = Canadian Maple [java] Location (x,y) = (3.0,5.0), Big Fur=Tree: Name = Big Fur [java] Location (x,y) = (1.0,1.0) [java] Part 05: TreeMap of trees [java] ========================= [java] {Big Fur=Tree: Name = Big Fur [java] Location (x,y) = (1.0,1.0), Canadian Maple=Tree: Name = Canadian Maple [java] Location (x,y) = (3.0,5.0), Weeping Willow=Tree: Name = Weeping Willow [java] Location (x,y) = (3.0,2.0) BUILD SUCCESSFUL Total time: 1 second prompt >> exit Please look at the source code carefully and answer the questions that follow: [2a] (5 pts). Draw and label a diagram that shows the organizational arrangement of java packages and user-defined java source code files. 14

15 [2b] (5 pts). Draw and label a diagram that shows the relationship among the Feature, Abstract- Feature, Location, Tree and TestScene classes. [2c] (5 pts). Draw and label a diagram showing the layout of memory generated by the statements in Part 01 of TestScene.java. 15

16 [2d] (5 pts). Draw and label a diagram showing the layout of memory after the statements in Part 02 have finished. [2e] (5 pts). What is the purpose of the syntax <Feature> in the statement: ArrayList<Feature> array = new ArrayList<Feature>(); 16

17 [2f] (5 pts). Explain why objects of type Tree can be added to an arraylist of features, i.e., ArrayList<Feature> array = new ArrayList<Feature>(); array.add( tree01 ); [2g] (5 pts). In what important way do ArrayLists differ from HashSets? [2h] (5 pts). Explain the purpose of each part in the statement: Map<String, Feature> map = new HashMap<String, Feature>(); 17

18 [2i] (5 pts). Draw and label a diagram showing the layout of memory generated by the statements in Part 04 of TestScene.java. [2j] (5 pts). In Part 05 of TestScene.java, what is the primary purpose of the HashMap to TreeMap conversion? 18

Department of Civil and Environmental Engineering, Spring Semester, ENCE 688R: Midterm Exam: 1 1/2 Hours, Open Book and Open Notes

Department of Civil and Environmental Engineering, Spring Semester, ENCE 688R: Midterm Exam: 1 1/2 Hours, Open Book and Open Notes Department of Civil and Environmental Engineering, Spring Semester, 2013 ENCE 688R: Midterm Exam: 1 1/2 Hours, Open Book and Open Notes Name : Question Points Score 1 30 2 30 3 40 Total 100 1 Question

More information

Department of Civil and Environmental Engineering, Spring Semester, ENCE 688R: Final Exam: 2 Hours, Open Book and Open Notes

Department of Civil and Environmental Engineering, Spring Semester, ENCE 688R: Final Exam: 2 Hours, Open Book and Open Notes Department of Civil and Environmental Engineering, Spring Semester, 2016 ENCE 688R: Final Exam: 2 Hours, Open Book and Open Notes Name : Question Points Score 1 100 Total 100 1 Question 1: 100 points Let

More information

Department of Civil and Environmental Engineering, Spring Semester, ENCE 688R: Midterm Exam: 1 1/2 Hours, Open Book and Open Notes

Department of Civil and Environmental Engineering, Spring Semester, ENCE 688R: Midterm Exam: 1 1/2 Hours, Open Book and Open Notes Department of Civil and Environmental Engineering, Spring Semester, 2016 ENCE 688R: Midterm Exam: 1 1/2 Hours, Open Book and Open Notes Name : Question Points Score 1 30 2 40 3 30 Total 100 1 Question

More information

Working with Objects and Classes

Working with Objects and Classes p. 1/6 ENCE 688R Civil Information Systems Working with Objects and Classes Mark Austin E-mail: austin@isr.umd.edu Department of Civil and Environmental Engineering, University of Maryland, College Park

More information

Department of Civil and Environmental Engineering, Spring Semester, ENCE 688R: Final Exam: 2 Hours, Open Book and Open Notes

Department of Civil and Environmental Engineering, Spring Semester, ENCE 688R: Final Exam: 2 Hours, Open Book and Open Notes Department of Civil and Environmental Engineering, Spring Semester, 2017 ENCE 688R: Final Exam: 2 Hours, Open Book and Open Notes Name : Question Points Score 1 50 2 30 3 20 Total 100 1 Question 1: 50

More information

Problem 8.1: Model rectangles with Vertices...

Problem 8.1: Model rectangles with Vertices... ------------------------------------------------------------------------- ENCE 688R: Solutions to Homework 2 March 2016 ------------------------------------------------------------------------- -------------------------------------------------------------------------

More information

Engineering Software Development in Java

Engineering Software Development in Java Engineering Software Development in Java Lecture Notes for ENCE 688R, Civil Information Systems Spring Semester, 2016 Mark Austin, Department of Civil and Enviromental Engineering, University of Maryland,

More information

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine Homework 6 Yuji Shimojo CMSC 330 Instructor: Prof. Reginald Y. Haseltine July 21, 2013 Question 1 What is the output of the following C++ program? #include #include using namespace

More information

CSE 143 Au04 Midterm 1 Page 1 of 9

CSE 143 Au04 Midterm 1 Page 1 of 9 CSE 143 Au04 Midterm 1 Page 1 of 9 Question 1. (4 points) When we re modifying Java code, some of the things we do will change the coupling between the class we re working on and other classes that it

More information

Practice Midterm 1. Problem Points Score TOTAL 50

Practice Midterm 1. Problem Points Score TOTAL 50 CS 120 Software Design I Spring 2019 Practice Midterm 1 University of Wisconsin - La Crosse February 25 NAME: Do not turn the page until instructed to do so. This booklet contains 10 pages including the

More information

CSE 8B Programming Assignments Spring Programming: You will have 5 files all should be located in a dir. named PA3:

CSE 8B Programming Assignments Spring Programming: You will have 5 files all should be located in a dir. named PA3: PROGRAMMING ASSIGNMENT 3: Read Savitch: Chapter 7 Programming: You will have 5 files all should be located in a dir. named PA3: ShapeP3.java PointP3.java CircleP3.java RectangleP3.java TriangleP3.java

More information

Recommended Group Brainstorm (NO computers during this time)

Recommended Group Brainstorm (NO computers during this time) Recommended Group Brainstorm (NO computers during this time) Good programmers think before they begin coding. Part I of this assignment involves brainstorming with a group of peers with no computers to

More information

CS 455 Midterm 2 Spring 2018 [Bono] Apr. 3, 2018

CS 455 Midterm 2 Spring 2018 [Bono] Apr. 3, 2018 Name: USC NetID (e.g., ttrojan): CS 455 Midterm 2 Spring 2018 [Bono] Apr. 3, 2018 There are 7 problems on the exam, with 59 points total available. There are 10 pages to the exam (5 pages double-sided),

More information

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

CS250 Intro to CS II. Spring CS250 - Intro to CS II 1 CS250 Intro to CS II Spring 2017 CS250 - Intro to CS II 1 Topics Virtual Functions Pure Virtual Functions Abstract Classes Concrete Classes Binding Time, Static Binding, Dynamic Binding Overriding vs Redefining

More information

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University Day 3 COMP 1006/1406A Summer 2016 M. Jason Hinek Carleton University today s agenda assignments 1 was due before class 2 is posted (be sure to read early!) a quick look back testing test cases for arrays

More information

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

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes. a and Interfaces Class Shape Hierarchy Consider the following class hierarchy Shape Circle Square Problem AND Requirements Suppose that in order to exploit polymorphism, we specify that 2-D objects must

More information

CMSC 433 Section 0101 Fall 2012 Midterm Exam #1

CMSC 433 Section 0101 Fall 2012 Midterm Exam #1 Name: CMSC 433 Section 0101 Fall 2012 Midterm Exam #1 Directions: Test is closed book, closed notes. Answer every question; write solutions in spaces provided. Use backs of pages for scratch work. Good

More information

CS 455 Midterm Exam 1 Spring 2015 [Bono] Thursday, Feb. 19, 2015

CS 455 Midterm Exam 1 Spring 2015 [Bono] Thursday, Feb. 19, 2015 Name: USC username (e.g., ttrojan): CS 455 Midterm Exam 1 Spring 2015 [Bono] Thursday, Feb. 19, 2015 There are 5 problems on the exam, with 50 points total available. There are 7 pages to the exam, including

More information

CS 113 MIDTERM EXAM 2 SPRING 2013

CS 113 MIDTERM EXAM 2 SPRING 2013 CS 113 MIDTERM EXAM 2 SPRING 2013 There are 18 questions on this test. The value of each question is: 1-15 multiple choice (3 pts) 17 coding problem (15 pts) 16, 18 coding problems (20 pts) You may get

More information

Java Classes & Primitive Types

Java Classes & Primitive Types Java Classes & Primitive Types Rui Moreira Classes Ponto (from figgeom) x : int = 0 y : int = 0 n Attributes q Characteristics/properties of classes q Primitive types (e.g., char, byte, int, float, etc.)

More information

Java Classes & Primitive Types

Java Classes & Primitive Types Java Classes & Primitive Types Rui Moreira Classes Ponto (from figgeom) x : int = 0 y : int = 0 n Attributes q Characteristics/properties of classes q Primitive types (e.g., char, byte, int, float, etc.)

More information

Object Oriented Programming

Object Oriented Programming Object Oriented Programming Debapriyo Majumdar Programming and Data Structure Lab M Tech CS I Semester I Indian Statistical Institute Kolkata August 7 and 14, 2014 Objects Real world objects, or even people!

More information

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit. Name CS 110 Practice Final Exam originally from Winter, 2003 Instructions: closed books, closed notes, open minds, 3 hour time limit. There are 4 sections for a total of 49 points. Part I: Basic Concepts,

More information

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017 Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor Sep 2017 Lecture 11: Inheritance and Polymorphism Part 1 Instructor: AbuKhleif, Mohammad Noor Sep 2017 Instructor AbuKhleif, Mohammad

More information

Java: Comment Text. Introduction. Concepts

Java: Comment Text. Introduction. Concepts Java: Comment Text Introduction Comment text is text included in source code that is ignored by the compiler and does not cause any machine-language object code to be generated. It is written into the

More information

Topic 10: The Java Collections Framework (and Iterators)

Topic 10: The Java Collections Framework (and Iterators) Topic 10: The Java Collections Framework (and Iterators) A set of interfaces and classes to help manage collections of data. Why study the Collections Framework? very useful in many different kinds of

More information

Final Exam CS 251, Intermediate Programming December 13, 2017

Final Exam CS 251, Intermediate Programming December 13, 2017 Final Exam CS 251, Intermediate Programming December 13, 2017 Name: NetID: Answer all questions in the space provided. Write clearly and legibly, you will not get credit for illegible or incomprehensible

More information

24. Inheritance. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

24. Inheritance. Java. Fall 2009 Instructor: Dr. Masoud Yaghini 24. Inheritance Java Fall 2009 Instructor: Dr. Masoud Yaghini Outline Superclasses and Subclasses Using the super Keyword Overriding Methods The Object Class References Superclasses and Subclasses Inheritance

More information

Chapter 14 Abstract Classes and Interfaces

Chapter 14 Abstract Classes and Interfaces Chapter 14 Abstract Classes and Interfaces 1 What is abstract class? Abstract class is just like other class, but it marks with abstract keyword. In abstract class, methods that we want to be overridden

More information

22. Inheritance. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

22. Inheritance. Java. Summer 2008 Instructor: Dr. Masoud Yaghini 22. Inheritance Java Summer 2008 Instructor: Dr. Masoud Yaghini Outline Superclasses and Subclasses Using the super Keyword Overriding Methods The Object Class References Inheritance Object-oriented programming

More information

F I N A L E X A M I N A T I O N

F I N A L E X A M I N A T I O N Faculty Of Computer Studies M257 Putting Java to Work F I N A L E X A M I N A T I O N Number of Exam Pages: (including this cover sheet( Spring 2011 April 4, 2011 ( 5 ) Time Allowed: ( 1.5 ) Hours Student

More information

CH. 2 OBJECT-ORIENTED PROGRAMMING

CH. 2 OBJECT-ORIENTED PROGRAMMING CH. 2 OBJECT-ORIENTED PROGRAMMING ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER (WILEY 2016) OBJECT-ORIENTED

More information

Chapter 9 - Object-Oriented Programming: Polymorphism

Chapter 9 - Object-Oriented Programming: Polymorphism Chapter 9 - Object-Oriented Programming: Polymorphism Polymorphism Program in the general Introduction Treat objects in same class hierarchy as if all superclass Abstract class Common functionality Makes

More information

MACS 261J Final Exam. Question: Total Points: Score:

MACS 261J Final Exam. Question: Total Points: Score: MACS 261J Final Exam May 5, 2008 Name: Question: 1 2 3 4 5 6 7 8 9 Total Points: 15 10 15 5 10 5 20 8 12 100 Score: Question 1............................................................. (15 points) (a)

More information

Inheritance (Deitel chapter 9)

Inheritance (Deitel chapter 9) Inheritance (Deitel chapter 9) 1 2 Plan Introduction Superclasses and Subclasses protected Members Constructors and Finalizers in Subclasses Software Engineering with Inheritance 3 Introduction Inheritance

More information

CS 101 Exam 2 Spring Id Name

CS 101 Exam 2 Spring Id Name CS 101 Exam 2 Spring 2005 Email Id Name This exam is open text book and closed notes. Different questions have different points associated with them. Because your goal is to maximize your number of points,

More information

The Nervous Shapes Example

The Nervous Shapes Example The Nervous Shapes Example This Example is taken from Dr. King s Java book 1 11.6 Abstract Classes Some classes are purely artificial, created solely so that subclasses can take advantage of inheritance.

More information

More Java Basics. class Vector { Object[] myarray;... //insert x in the array void insert(object x) {...} Then we can use Vector to hold any objects.

More Java Basics. class Vector { Object[] myarray;... //insert x in the array void insert(object x) {...} Then we can use Vector to hold any objects. More Java Basics 1. INHERITANCE AND DYNAMIC TYPE-CASTING Java performs automatic type conversion from a sub-type to a super-type. That is, if a method requires a parameter of type A, we can call the method

More information

mith College Computer Science Sets and Hashing CSC212 Fall 2014 Dominique Thiébaut

mith College Computer Science Sets and Hashing CSC212 Fall 2014 Dominique Thiébaut mith College Computer Science Sets and Hashing CSC22 Fall 204 Dominique Thiébaut dthiebaut@smith.edu The Problem: Large amount of live tweets Want the list of all tweeters Each only listed once What data

More information

PASS4TEST IT 인증시험덤프전문사이트

PASS4TEST IT 인증시험덤프전문사이트 PASS4TEST IT 인증시험덤프전문사이트 http://www.pass4test.net 일년동안무료업데이트 Exam : 1z0-809 Title : Java SE 8 Programmer II Vendor : Oracle Version : DEMO Get Latest & Valid 1z0-809 Exam's Question and Answers 1 from

More information

(a) Write the signature (visibility, name, parameters, types) of the method(s) required

(a) Write the signature (visibility, name, parameters, types) of the method(s) required 1. (6 pts) Is the final comprehensive? 1 2. (6 pts) Java has interfaces Comparable and Comparator. As discussed in class, what is the main advantage of Comparator? 3. (6 pts) We can use a comparator in

More information

Page 1 of 16. Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Page 1 of 16. Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. Page 1 of 16 HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2005 FINAL EXAMINATION 9am to 12noon, 19 DECEMBER 2005 Instructor: Alan McLeod If

More information

Lecture 10: Introduction to Inheritance

Lecture 10: Introduction to Inheritance Lecture 10: Introduction to Inheritance CS427: Programming in C++ Lecture 10.2 11am, 12th March 2012 CS427 Lecture 10: Introduction to Inheritance 1/17 In today s class 1 Inheritance protected 2 Replacing

More information

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ June Exam

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ June Exam Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2009 June Exam Question Max Internal

More information

Midterm Exam 2 CS 455, Spring 2015

Midterm Exam 2 CS 455, Spring 2015 Name: USC NetId (e.g., ttrojan): Midterm Exam 2 CS 455, Spring 2015 April 7, 2015 There are 7 problems on the exam, with 60 points total available. There are 8 pages to the exam, including this one; make

More information

CSCI 1101 Winter 2017 Laboratory No Submission deadline is p.m. (5 minutes to midnight) on Saturday, February 4th, 2017.

CSCI 1101 Winter 2017 Laboratory No Submission deadline is p.m. (5 minutes to midnight) on Saturday, February 4th, 2017. CSCI 1101 Winter 2017 Laboratory No. 3 This lab is a continuation of the concepts of object-oriented programming, specifically the use of static variables and static methods, and object interactions. If

More information

CSE 373 Spring 2010: Midterm #2 (closed book, closed notes, NO calculators allowed)

CSE 373 Spring 2010: Midterm #2 (closed book, closed notes, NO calculators allowed) Name: Email address: CSE 373 Spring 2010: Midterm #2 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial

More information

CS151 Principles of Computer Science I Fall 2018 Homework 6 S

CS151 Principles of Computer Science I Fall 2018 Homework 6 S 1. Exercise 19 : double Exercise 20 : String CS151 Principles of Computer Science I Fall 2018 Homework 6 S Exercise 21 : foo1 is a class method since it is declared static Exercise 22 : foo2 is an instance

More information

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle Boggle If you are not familiar with the game Boggle, the game is played with 16 dice that have letters on all faces. The dice are randomly deposited into a four-by-four grid so that the players see the

More information

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total. Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total. Name: ID: Problem 1) (8 points) For the following code segment, what are the values of i, j, k, and d, after the segment

More information

CS 113 PRACTICE FINAL

CS 113 PRACTICE FINAL CS 113 PRACTICE FINAL There are 13 questions on this test. The value of each question is: 1-10 multiple choice (4 pt) 11-13 coding problems (20 pt) You may get partial credit for questions 11-13. If you

More information

CS170 Introduction to Computer Science Midterm 2

CS170 Introduction to Computer Science Midterm 2 CS170 Introduction to Computer Science Midterm 2 03/25/2009 Name: Solution You are to honor the Emory Honor Code. This is a closed book and closednotes exam, and you are not to use any other resource than

More information

CS 102/107 - Introduction to Programming Midterm Exam #2 - Prof. Reed Spring 2011

CS 102/107 - Introduction to Programming Midterm Exam #2 - Prof. Reed Spring 2011 CS 102/107 - Introduction to Programming Midterm Exam #2 - Prof. Reed Spring 2011 What is your name?: This test has the following sections: I. True/False... 60 points; (30 questions, 2 points each) II.

More information

KING FAHD UNIVERSITY OF PETROLEUM & MINERALS Information and Computer Science Department

KING FAHD UNIVERSITY OF PETROLEUM & MINERALS Information and Computer Science Department KING FAHD UNIVERSITY OF PETROLEUM & MINERALS Information and Computer Science Department ICS-201 Introduction to Computer Science Lab 03: Java Virtual Machines and Java Packages Objectives: In this lab,

More information

CLASSES AND OBJECTS. Summer 2018

CLASSES AND OBJECTS. Summer 2018 CLASSES AND OBJECTS Summer 2018 OBJECT BASICS Everything in Java is part of a class This includes all methods (functions) Even the main() function is part of a class Classes are declared similar to C++

More information

M257 Putting Java to work

M257 Putting Java to work Arab Open University Faculty of Computer Studies Course Examination Spring 2010 M257 Putting Java to work Exam date: May 2010 Time allowed: 2.5 hours Form: X A B Student name/ Section number: Tutor Name:

More information

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each Your Name: Your Pitt (mail NOT peoplesoft) ID: Part Question/s Points available Rubric Your Score A 1-6 6 1 pt each B 7-12 6 1 pt each C 13-16 4 1 pt each D 17-19 5 1 or 2 pts each E 20-23 5 1 or 2 pts

More information

Instance Method Development Demo

Instance Method Development Demo Instance Method Development Demo Write a class Person with a constructor that accepts a name and an age as its argument. These values should be stored in the private attributes name and age. Then, write

More information

CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2015

CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2015 CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2015 Name: This exam consists of 6 problems on the following 7 pages. You may use your single-sided handwritten 8 ½ x 11 note sheet during

More information

CITS1001 week 6 Libraries

CITS1001 week 6 Libraries CITS1001 week 6 Libraries Arran Stewart April 12, 2018 1 / 52 Announcements Project 1 available mid-semester test self-assessment 2 / 52 Outline Using library classes to implement some more advanced functionality

More information

CS 1316 Exam 1 Summer 2009

CS 1316 Exam 1 Summer 2009 1 / 8 Your Name: I commit to uphold the ideals of honor and integrity by refusing to betray the trust bestowed upon me as a member of the Georgia Tech community. CS 1316 Exam 1 Summer 2009 Section/Problem

More information

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Name: Email address: CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial

More information

CIS 265 Exam 2 First Name Last Name

CIS 265 Exam 2 First Name Last Name CIS 265 Exam 2 First Name Last Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Which of the data types below does not allow duplicates? 1)

More information

QUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer

QUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer QUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer STUDENT NAME: ID: The exam consists of five questions. There are a total of 10 points. You may use the back

More information

Midterm Exam 2 CS 455, Fall 2013

Midterm Exam 2 CS 455, Fall 2013 Name: USC loginid (e.g., ttrojan): Midterm Exam 2 CS 455, Fall 2013 Wednesday, November 6, 2013 There are 9 problems on the exam, with 58 points total available. There are 8 pages to the exam, including

More information

1.00 Lecture 8. Using An Existing Class, cont.

1.00 Lecture 8. Using An Existing Class, cont. .00 Lecture 8 Classes, continued Reading for next time: Big Java: sections 7.9 Using An Existing Class, cont. From last time: is a Java class used by the BusTransfer class BusTransfer uses objects: First

More information

CPSC 324 Topics in Java Programming

CPSC 324 Topics in Java Programming CPSC 324 Topics in Java Programming Lecture 24 Today Final exam review Java packages and jar files Reminder Group projects on Thursday! Reading Assignment Core: Ch. 10 pp. 493-500 (Jar files) Core: Ch.

More information

Expanded Guidelines on Programming Style and Documentation

Expanded Guidelines on Programming Style and Documentation Page 1 of 5 Expanded Guidelines on Programming Style and Documentation Introduction Introduction to Java Programming, 5E Y. Daniel Liang liang@armstrong.edu Programming style deals with the appearance

More information

Part 1. Programming Output [Polymorphism]

Part 1. Programming Output [Polymorphism] KINGDOM OF SAUDI ARABIA Ministry of Higher Education Prince Sultan University College of Computer and Information Sciences المملكة العربية السعودية وزارة التعليم العالي جامعة الا مري سلطان كلية علوم الحاسب

More information

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

1. Which of the following is the correct expression of character 4? a. 4 b. 4 c. '\0004' d. '4' Practice questions: 1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4' 2. Will System.out.println((char)4) display 4? a. Yes b. No 3. The expression "Java

More information

CS 455 Midterm Exam 1 Fall 2017 [Bono] Thursday, Sep. 28, 2017

CS 455 Midterm Exam 1 Fall 2017 [Bono] Thursday, Sep. 28, 2017 Name: USC NetID (e.g., ttrojan): CS 455 Midterm Exam 1 Fall 2017 [Bono] Thursday, Sep. 28, 2017 There are 6 problems on the exam, with 55 points total available. There are 10 pages to the exam (5 pages

More information

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination Monday, March 9, 2009 Examiners: Mathieu Petitpas [Section 1] 18:30

More information

CS 101 Exam 1 Spring 200 Id Name

CS 101 Exam 1 Spring 200  Id Name This exam is open text book and closed notes. Different questions have different points associated with them with later occurring questions having more worth than the beginning questions. Because your

More information

CPSC 233 Final Exam, Winter 2003 DEPARTMENT OF COMPUTER SCIENCE THE UNIVERSITY OF CALGARY Time: 120 minutes 100 marks total L02, L03, L04

CPSC 233 Final Exam, Winter 2003 DEPARTMENT OF COMPUTER SCIENCE THE UNIVERSITY OF CALGARY Time: 120 minutes 100 marks total L02, L03, L04 CPSC 233 Final Exam, Winter 2003 DEPARTMENT OF COMPUTER SCIENCE THE UNIVERSITY OF CALGARY Time: 120 minutes 100 marks total L02, L03, L04 First Name Last Name Check the box to indicate the lecture that

More information

Java Object Oriented Design. CSC207 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014 Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code

More information

Assumptions. History

Assumptions. History Assumptions A Brief Introduction to Java for C++ Programmers: Part 1 ENGI 5895: Software Design Faculty of Engineering & Applied Science Memorial University of Newfoundland You already know C++ You understand

More information

Interfaces. An interface defines a set of methods. An interface declaration contains signatures, but no implementations.

Interfaces. An interface defines a set of methods. An interface declaration contains signatures, but no implementations. Interface Interface definition Interface implementation by classes Benefits of interfaces Implementation of multiple interface Java Collection Framework Interfaces An interface defines a set of methods.

More information

1 Method Signatures and Overloading (3 minutes, 2 points)

1 Method Signatures and Overloading (3 minutes, 2 points) CS180 Spring 2010 Exam 1 Solutions, 15 February, 2010 Prof. Chris Clifton Turn Off Your Cell Phone. Use of any electronic device during the test is prohibited. Time will be tight. If you spend more than

More information

CISC 3115 TY3. C09a: Inheritance. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 9/20/2018 CUNY Brooklyn College

CISC 3115 TY3. C09a: Inheritance. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 9/20/2018 CUNY Brooklyn College CISC 3115 TY3 C09a: Inheritance Hui Chen Department of Computer & Information Science CUNY Brooklyn College 9/20/2018 CUNY Brooklyn College 1 Outline Inheritance Superclass/supertype, subclass/subtype

More information

CSCI 136 Programming Exam #2 Fundamentals of Computer Science II Spring 2012

CSCI 136 Programming Exam #2 Fundamentals of Computer Science II Spring 2012 CSCI 136 Programming Exam #2 Fundamentals of Computer Science II Spring 2012 This part of the exam is like a mini- programming assignment. You will create a program, compile it, and debug it as necessary.

More information

INTRODUCTION TO DATA AND PROCEDURE

INTRODUCTION TO DATA AND PROCEDURE INTRODUCTION TO DATA AND PROCEDURE In this book, our goal is to understand computation. In particular, we want to be able to take any computational problem and produce a technique for solving it that is

More information

EXAMINATIONS 2011 Trimester 2, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

EXAMINATIONS 2011 Trimester 2, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2011 Trimester 2, MID-TERM TEST COMP103 Introduction

More information

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007 Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2007 Final Examination Question Max

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 24 October 29, 2018 Arrays, Java ASM Chapter 21 and 22 Announcements HW6: Java Programming (Pennstagram) Due TOMORROW at 11:59pm Reminder: please complete

More information

Exploring the Java API, Packages & Collections

Exploring the Java API, Packages & Collections 6.092 - Introduction to Software Engineering in Java Lecture 7: Exploring the Java API, Packages & Collections Tuesday, January 29 IAP 2008 Cite as: Evan Jones, Olivier Koch, and Usman Akeju, course materials

More information

Rules and syntax for inheritance. The boring stuff

Rules and syntax for inheritance. The boring stuff Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for

More information

Konzepte von Programmiersprachen

Konzepte von Programmiersprachen Konzepte von Programmiersprachen Chapter 9: Objects and Classes Peter Thiemann Universität Freiburg 9. Juli 2009 Konzepte von Programmiersprachen 1 / 22 Objects state encapsulation (instance vars, fields)

More information

BSc. (Hons.) Software Engineering. Examinations for / Semester 2

BSc. (Hons.) Software Engineering. Examinations for / Semester 2 BSc. (Hons.) Software Engineering Cohort: BSE/04/PT Examinations for 2005-2006 / Semester 2 MODULE: OBJECT ORIENTED PROGRAMMING MODULE CODE: BISE050 Duration: 2 Hours Reading Time: 5 Minutes Instructions

More information

CS 455 Final Exam Spring 2018 [Bono] May 8, 2018

CS 455 Final Exam Spring 2018 [Bono] May 8, 2018 Name: USC NetID (e.g., ttrojan): CS 455 Final Exam Spring 2018 [Bono] May 8, 2018 There are 9 problems on the exam, with 74 points total available. There are 12 pages to the exam (6 pages double-sided),

More information

1.00 Lecture 13. Inheritance

1.00 Lecture 13. Inheritance 1.00 Lecture 13 Inheritance Reading for next time: Big Java: sections 10.5-10.6 Inheritance Inheritance allows you to write new classes based on existing (super or base) classes Inherit super class methods

More information

Java Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding

Java Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding Java Class Design Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding eugeny.berkunsky@gmail.com http://www.berkut.mk.ua Objectives Implement encapsulation Implement inheritance

More information

Last Name: Circle One: OCW Non-OCW

Last Name: Circle One: OCW Non-OCW First Name: AITI 2004: Exam 1 June 30, 2004 Last Name: Circle One: OCW Non-OCW Read Instructions Carefully! This is a 3 hour closed book exam. No calculators are allowed. Please write clearly if we cannot

More information

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

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner. HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all

More information

Part 11 Object Oriented Programming: Inheritance

Part 11 Object Oriented Programming: Inheritance 1 Part 11 Object Oriented Programming: Inheritance 2003 Prentice Hall, Inc. All rights reserved. Main concepts to be covered 2 Superclasses and Subclasses protected Members Relationship between Superclasses

More information

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods.

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods. Inheritance Inheritance is the act of deriving a new class from an existing one. Inheritance allows us to extend the functionality of the object. The new class automatically contains some or all methods

More information

The FacebookPerson Example. Dr. Xiaolin Hu CSC 2310, Spring 2015

The FacebookPerson Example. Dr. Xiaolin Hu CSC 2310, Spring 2015 The FacebookPerson Example Dr. Xiaolin Hu CSC 2310, Spring 2015 Motivation Whenever you are happy, update your facebook! Start from Simple A Facebook Person Class A test class public class FacebookPerson{

More information

Practice Midterm 1 Answer Key

Practice Midterm 1 Answer Key CS 120 Software Design I Fall 2018 Practice Midterm 1 Answer Key University of Wisconsin - La Crosse Due Date: October 5 NAME: Do not turn the page until instructed to do so. This booklet contains 10 pages

More information

Welcome. Java Programming I CIS 325. CIS 325 Java Programming I. Week 6 Java Classes. Inheritance and Polymorphism. Christopher K.

Welcome. Java Programming I CIS 325. CIS 325 Java Programming I. Week 6 Java Classes. Inheritance and Polymorphism. Christopher K. Welcome Java Programming I CIS 325 Week 6 Java Classes Inheritance and Polymorphism Christopher K. Burns Agenda Tonight s agenda Classes Inheritance Polymorphism MidTerm Review Homework Review Home Work

More information

Example: Fibonacci Numbers

Example: Fibonacci Numbers Example: Fibonacci Numbers Write a program which determines F n, the (n + 1)-th Fibonacci number. The first 10 Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, and 34. The sequence of Fibonacci numbers

More information

Linked Lists. References and objects

Linked Lists. References and objects Linked Lists slides created by Marty Stepp http://www.cs.washington.edu/143/ Modified by Sarah Heckman Reading: RS Chapter 16 References and objects In Java, objects and arrays use reference semantics.

More information