ENGR 2710U Midterm Exam UOIT SOLUTION SHEET

Size: px
Start display at page:

Download "ENGR 2710U Midterm Exam UOIT SOLUTION SHEET"

Transcription

1 SOLUTION SHEET ENGR 2710U: Object Oriented Programming & Design Midterm Exam October 19, 2012, Duration: 80 Minutes (9 Pages, 14 questions, 100 Marks) Instructor: Dr. Kamran Sartipi Name: Student Number: 1) For each part of a computer listed below, name two examples? [8 Marks] 2 mark each item (0.5 each example). Memory: RAM, ROM, EPROM, DRAM, SRAM I/O: Hard disk, CD, DVD, Monitor, Keyboard, Modem, Printer Computer Bus: Address, Data, Control Hardware Driver: Disk driver, Graphics driver, Printer driver, Internet driver, 2) What is the output when the following code is executed? [3 Marks] System.out.println(15/6); (a) 2.5 (b) 3.0 (c) 2 (d) 0 3) A hypothetical class Person contain the following instance variables [4 Marks] String name int age A default constructor sets name= Lucy and age = 20. A method changename (String newname) changes the instance variable name to the Page 1 of 9

2 value of newname. A method printname() prints the instance variable name. What is the output of the following code? Person p1= new Person(); Person p2 = p1; p1.changename( Smith ); p2.printname(); (a) name (b) NULL (c) Marge (d) Smith 4) What is the value of string mycourse at the end? [3 Marks] String mycourse = Object Oriented Programming ; String mycourse = mycourse.touppercase(); Object Oriented Programming Note: the method touppercase() returns a reference to a new string OBJECT ORIENTED PROGRAMMING, but the original string Object Oriented Programming remains unchanged. 5) Find the errors in the following if statements. [8 Marks] Each item a to d, 2 marks. a) if (1 + x > Math.pow(x, Math.sqrt(2))) y = y + 2 ; b) if (x == 1) y++; else if (x == 2) y = y +2; c) int x = Integer.parseInt(input); if (x!= null) y = y + x; x is integer and can not be null. Null is for object references. d) if (x==0 && y == 0) x = 1; y = 1; Page 2 of 9

3 6) Answer to the following questions. [10 Marks] a: 3 marks; b: 3 marks; c: 4 marks. a) What is the this reference? Why do we use it? Within an instance method or a constructor, this is a reference to the current object the object whose method or constructor is being called. You can refer to any member of the current object from within an instance method or a constructor by using this. Distinguish between local variable and instance variable Clarification of documentation b) What is the method below intended to do? Fix the security flaw in the code and write the changes below. The method is intended to transfer the amount from this account to another account with object reference that. this.balance = this.balance amount; that.deposit(amount); c) Show how you would use myprog() method in a class Tester which includes a main method (public static void main (String[] args)), by creating two objects of BankAccount class and a print statement (System.out.println(.)). public class BankAccount private double balance; public void myprog (BankAccount that, double amount) this.balance = this.balance - amount; that.balance = that.balance + amount; public class Tester public static void main(string[] args) BankAccount saving = new BankAccount(1000); BankAccount checking = new BankAccount(2000); saving.myprog(checking, 300); Page 3 of 9

4 7) For each statement below, indicate whether it is False or True. [12 Marks] In case of False briefly explain why. 3 marks each part. a) Encapsulation or Information Hiding is the process of hiding object data, and providing methods to hide those data. False.. method can not hide data. The Access Specifier private hides data b) To encapsulate data, the instance variables must be declared as private. True c) The only way for other objects to change the content of an object s instance variable is to change the access specifier from private to public. False. They must use the mutator methods of that object to change the content of the object. d) You can instantiate an object to generate several classes of the same type. False. The opposite, you instantiate a class to generate several objects of the same type. 8) For each statement below, indicate whether it is False or True. In case of False briefly explain why. [12 Marks] 3 marks each part. a) final and static final are used to declare class constant variables to be used by public. False, final is used for method level, and static final is used for class level. They define constants. b) Scanner in = new Scanner (System.in); expands the capability of System.in to input different types of data. True. Page 4 of 9

5 c) We compare two floating-point numbers f1 and f2 as f1.equals(f2) since we don t know exact numbers stored in them due to rounding error. False, f1.equals(f2) id for strings and objects, not numbers. d) For objects, we use == to test object contents; and we use equals to test the object s references. False, we use == to the object s references; and we use equals to test object contents 9) Convert the following for loop to an equivalent while loop. [5 Marks] for (int i = 1; i <= n; i++) double interest = balance * rate / 100; balance = balance + interest; int i=1; while (i<=n) double interest = balance * rate/100; balance = balance + interest; i++; 10) The following method has several conventional, syntactical, and logical errors. Find five of them and rewrite the method in the box below it. What is the intended operation of this method? [5 Marks] Page 5 of 9

6 public string TriAngle() string R = ""; int J = 0.0; for (int i = 1, i <= width, i++); J = i; // Make triangle row for (int i = 1, i <= J, i++); R = R + "[ ; R = R + ]"; R = R + "\n"; return R; public string triangle() string r = ""; int j = 0; for (int i = 1; i <= width; i++) j = i; // Make triangle row for (int k = 1, k <= j, k++); r = r + "[ ; r = r + ]"; r = r + "\n"; return r; Note: finding the same bug more than once does not receive mark. One mark per bug. Page 6 of 9

7 11) What is the output of the following code? [8 Marks] public class testfor public static void main(string[] args) for (int i = 1; i <= 3; i++) for (int j = 1; j <= 5; j++) if (j % 2 == 0) System.out.print("#"); else System.out.print("^"); System.out.println(); ^ # ^ # ^ ^ # ^ # ^ ^ # ^ # ^ 12) What do the following program segments print? Or, if there is an error, describe the error and specify whether it is detected at compile-time or at run-time. [6 Marks] 2 marks each. a) double[] a = new double[10]; System.out.println(a[0]); b) double[] b = new double[10]; System.out.println(b[10]); c) double[] c; System.out.println(c[0]); a) 0 b) a run-time error: array index out of bounds c) a compile-time error: c is not initialized Page 7 of 9

8 13) The BankAccount class has three interfaces as follows: [4 Marks] public void deposit(double amount) public void withdraw(double amount) public double getbalance() harryschecking is an object of BankAccount and has some balance. Write one line of code to empty the account? harryschecking.withdraw(harryschecking.getbalance()) 14) Answer the following questions with respect to the array list [12 Marks] ArrayList<Double> values which has several items in it. a: 3 marks; b: 2 marks; c: 7 marks. int myvar = 0; boolean flag = false; while (myvar < values.size() &&!flag) if (values.get(myvar) > 555) flag = true; else myvar++; if (flag) System.out.println(myVar); else System.out.println(flag); a) What does the above code do? It locates and prints the position of the first element in the ArrayList that is larger than 555. Otherwise, it prints false. b) What happens to the results if in the last two lines the brackets ( ) are removed. Nothing. The brackets are extra since each if and else has only one statement in their bodies. Page 8 of 9

9 c) Rewrite the code using enhanced For Loop (also called for each loop ). int myvar=0; boolean flag = false; for(double value : values) if (myvar < values.size() &&!flag && value <= 100) myvar++; else flag = true; if(flag) System.out.println(myVar); else System.out.println(flag); END GOOD LUCK! Page 9 of 9

Problem Grade Total

Problem Grade Total CS 101, Prof. Loftin: Final Exam, May 11, 2009 Name: All your work should be done on the pages provided. Scratch paper is available, but you should present everything which is to be graded on the pages

More information

McGill University School of Computer Science COMP-202A Introduction to Computing 1

McGill University School of Computer Science COMP-202A Introduction to Computing 1 McGill University School of Computer Science COMP-202A Introduction to Computing 1 Midterm Exam Thursday, October 26, 2006, 18:00-20:00 (6:00 8:00 PM) Instructors: Mathieu Petitpas, Shah Asaduzzaman, Sherif

More information

Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 45 Obtained Marks:

Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 45 Obtained Marks: كلية الحاسبات وتقنية المعلوما Exam 1 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: October 18, 2015 Student Name: Student ID: Total Marks: 45 Obtained Marks: Instructions: Do not open this

More information

Lecture 06: Classes and Objects

Lecture 06: Classes and Objects Accelerating Information Technology Innovation http://aiti.mit.edu Lecture 06: Classes and Objects AITI Nigeria Summer 2012 University of Lagos. What do we know so far? Primitives: int, float, double,

More information

Fall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.

Fall CS 101: Test 2 Name UVA  ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17. Grading Page 1 / 4 Page3 / 20 Page 4 / 13 Page 5 / 10 Page 6 / 26 Page 7 / 17 Page 8 / 10 Total / 100 1. (4 points) What is your course section? CS 101 CS 101E Pledged Page 1 of 8 Pledged The following

More information

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1 Name SOLUTION Page Points Score 2 15 3 8 4 18 5 10 6 7 7 7 8 14 9 11 10 10 Total 100 1 P age 1. Program Traces (41 points, 50 minutes)

More information

Introduction to Computer Science and Object-Oriented Programming

Introduction to Computer Science and Object-Oriented Programming COMP 111 Introduction to Computer Science and Object-Oriented Programming Values Judgment Programs Manipulate Values Inputs them Stores them Calculates new values from existing ones Outputs them In Java

More information

Chapter 6 Lab Classes and Objects

Chapter 6 Lab Classes and Objects Lab Objectives Chapter 6 Lab Classes and Objects Be able to declare a new class Be able to write a constructor Be able to write instance methods that return a value Be able to write instance methods that

More information

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003 1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 7, 2003 Name: Email Address: TA: Section: You have 90 minutes to complete this exam. For coding questions, you do not need to

More information

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam Page 0 German University in Cairo April 6, 2017 Media Engineering and Technology Faculty Prof. Dr. Slim Abdennadher CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam Bar Code

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

THE UNIVERSITY OF WESTERN AUSTRALIA. School of Computer Science & Software Engineering CITS1001 OBJECT-ORIENTED PROGRAMMING AND SOFTWARE ENGINEERING

THE UNIVERSITY OF WESTERN AUSTRALIA. School of Computer Science & Software Engineering CITS1001 OBJECT-ORIENTED PROGRAMMING AND SOFTWARE ENGINEERING THE UNIVERSITY OF WESTERN AUSTRALIA School of Computer Science & Software Engineering CITS1001 OBJECT-ORIENTED PROGRAMMING AND SOFTWARE ENGINEERING SAMPLE TEST APRIL 2012 This Paper Contains: 12 Pages

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 UNIVERSITY OF WESTERN AUSTRALIA. School of Computer Science & Software Engineering CITS1001 OBJECT-ORIENTED PROGRAMMING AND SOFTWARE ENGINEERING

THE UNIVERSITY OF WESTERN AUSTRALIA. School of Computer Science & Software Engineering CITS1001 OBJECT-ORIENTED PROGRAMMING AND SOFTWARE ENGINEERING THE UNIVERSITY OF WESTERN AUSTRALIA School of Computer Science & Software Engineering CITS1001 OBJECT-ORIENTED PROGRAMMING AND SOFTWARE ENGINEERING MID-SEMESTER TEST Semester 1, 2012 CITS1001 This Paper

More information

AP CS Unit 3: Control Structures Notes

AP CS Unit 3: Control Structures Notes AP CS Unit 3: Control Structures Notes The if and if-else Statements. These statements are called control statements because they control whether a particular block of code is executed or not. Some texts

More information

APCS Semester #1 Final Exam Practice Problems

APCS Semester #1 Final Exam Practice Problems Name: Date: Per: AP Computer Science, Mr. Ferraro APCS Semester #1 Final Exam Practice Problems The problems here are to get you thinking about topics we ve visited thus far in preparation for the semester

More information

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below. C212 Early Evaluation Exam Mon Feb 10 2014 Name: Please provide brief (common sense) justifications with your answers below. 1. What is the type (and value) of this expression: 5 * (7 + 4 / 2) 2. What

More information

Agenda: Notes on Chapter 3. Create a class with constructors and methods.

Agenda: Notes on Chapter 3. Create a class with constructors and methods. Bell Work 9/19/16: How would you call the default constructor for a class called BankAccount? Agenda: Notes on Chapter 3. Create a class with constructors and methods. Objectives: To become familiar with

More information

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Last Class CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides in this

More information

Chapter 6 Lab Classes and Objects

Chapter 6 Lab Classes and Objects Gaddis_516907_Java 4/10/07 2:10 PM Page 51 Chapter 6 Lab Classes and Objects Objectives Be able to declare a new class Be able to write a constructor Be able to write instance methods that return a value

More information

Lecture 7 Objects and Classes

Lecture 7 Objects and Classes Lecture 7 Objects and Classes An Introduction to Data Abstraction MIT AITI June 13th, 2005 1 What do we know so far? Primitives: int, double, boolean, String* Variables: Stores values of one type. Arrays:

More information

Data Structures. Data structures. Data structures. What is a data structure? Simple answer: a collection of data equipped with some operations.

Data Structures. Data structures. Data structures. What is a data structure? Simple answer: a collection of data equipped with some operations. Data Structures 1 Data structures What is a data structure? Simple answer: a collection of data equipped with some operations. Examples Lists Strings... 2 Data structures In this course, we will learn

More information

Encapsulation. Mason Vail Boise State University Computer Science

Encapsulation. Mason Vail Boise State University Computer Science Encapsulation Mason Vail Boise State University Computer Science Pillars of Object-Oriented Programming Encapsulation Inheritance Polymorphism Abstraction (sometimes) Object Identity Data (variables) make

More information

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks: كلية الحاسبات وتقنية المعلوما Exam 2 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: November 22, 2015 Student Name: Student ID: Total Marks: 40 Obtained Marks: Instructions: Do not open this

More information

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ Test 2. Question Max Mark Internal External

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ Test 2. Question Max Mark Internal External 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 Test 2 Question Max Mark Internal

More information

CSE 142, Autumn 2008 Midterm Exam, Friday, October 31, 2008

CSE 142, Autumn 2008 Midterm Exam, Friday, October 31, 2008 CSE 142, Autumn 2008 Midterm Exam, Friday, October 31, 2008 Name: Section: Student ID #: TA: You have 50 minutes to complete this exam. You may receive a deduction if you keep working after the instructor

More information

Arrays and Array Lists

Arrays and Array Lists Arrays and Array Lists Advanced Programming ICOM 4015 Lecture 7 Reading: Java Concepts Chapter 8 Fall 2006 Slides adapted from Java Concepts companion slides 1 Lecture Goals To become familiar with using

More information

Give one example where you might wish to use a three dimensional array

Give one example where you might wish to use a three dimensional array CS 110: INTRODUCTION TO COMPUTER SCIENCE SAMPLE TEST 3 TIME ALLOWED: 60 MINUTES Student s Name: MAXIMUM MARK 100 NOTE: Unless otherwise stated, the questions are with reference to the Java Programming

More information

Chapter 8. Arrays and Array Lists. Chapter Goals. Chapter Goals. Arrays. Arrays. Arrays

Chapter 8. Arrays and Array Lists. Chapter Goals. Chapter Goals. Arrays. Arrays. Arrays Chapter 8 Arrays and Array Lists Chapter Goals To become familiar with using arrays and array lists To learn about wrapper classes, auto-boxing and the generalized for loop To study common array algorithms

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

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch Problem Solving Creating a class from scratch 1 Recipe for Writing a Class 1. Write the class boilerplate stuff 2. Declare Fields 3. Write Creator(s) 4. Write accessor methods 5. Write mutator methods

More information

CSE 142, Spring 2010 Final Exam Wednesday, June 9, Name: Student ID #: Rules:

CSE 142, Spring 2010 Final Exam Wednesday, June 9, Name: Student ID #: Rules: CSE 142, Spring 2010 Final Exam Wednesday, June 9, 2010 Name: Section: Student ID #: TA: Rules: You have 110 minutes to complete this exam. You may receive a deduction if you keep working after the instructor

More information

Implementing Classes (P1 2006/2007)

Implementing Classes (P1 2006/2007) Implementing Classes (P1 2006/2007) Fernando Brito e Abreu (fba@di.fct.unl.pt) Universidade Nova de Lisboa (http://www.unl.pt) QUASAR Research Group (http://ctp.di.fct.unl.pt/quasar) Chapter Goals To become

More information

CSE115 Introduction to Computer Science I Coding Exercise #7 Retrospective Fall 2017

CSE115 Introduction to Computer Science I Coding Exercise #7 Retrospective Fall 2017 This week the main activity was a quiz activity, with a structure similar to our Friday lecture activities. The retrospective for the quiz is in Quiz-07- retrospective.pdf This retrospective explores the

More information

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade; Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The

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

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 24, Name: KEY 1

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 24, Name: KEY 1 CSC 1051 Algorithms and Data Structures I Midterm Examination February 24, 2014 Name: KEY 1 Question Value Score 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 10 TOTAL 100 Please answer questions in

More information

data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it.

data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it. Introduction to JAVA JAVA is a programming language which is used in Android App Development. It is class based and object oriented programming whose syntax is influenced by C++. The primary goals of JAVA

More information

OBJECTS AND CLASSES CHAPTER. Final Draft 10/30/2011. Slides by Donald W. Smith TechNeTrain.com

OBJECTS AND CLASSES CHAPTER. Final Draft 10/30/2011. Slides by Donald W. Smith TechNeTrain.com CHAPTER 8 OBJECTS AND CLASSES Slides by Donald W. Smith TechNeTrain.com Final Draft 10/30/2011 Chapter Goals To understand the concepts of classes, objects and encapsulation To implement instance variables,

More information

CSIS 10A Practice Final Exam Name:

CSIS 10A Practice Final Exam Name: CSIS 10A Practice Final Exam Name: Multiple Choice: Each question is worth 2 points. Circle the letter of the best answer for the following questions. 1. For the following declarations: int area; String

More information

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016 Name: USC NetID (e.g., ttrojan): CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016 There are 5 problems on the exam, with 56 points total available. There are 10 pages to the exam (5 pages

More information

Programming with Java

Programming with Java Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules

More information

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

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018 Object-oriented programming 1 and data-structures CS/ENGRD 2110 SUMMER 2018 Lecture 1: Types and Control Flow http://courses.cs.cornell.edu/cs2110/2018su Lecture 1 Outline 2 Languages Overview Imperative

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

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

Introduction to Objects. James Brucker

Introduction to Objects. James Brucker Introduction to Objects James Brucker What is an Object? An object is a program element that encapsulates both data and behavior. An object contains both data and methods that operate on the data. Objects

More information

AP COMPUTER SCIENCE A

AP COMPUTER SCIENCE A AP COMPUTER SCIENCE A CONTROL FLOW Aug 28 2017 Week 2 http://apcs.cold.rocks 1 More operators! not!= not equals to % remainder! Goes ahead of boolean!= is used just like == % is used just like / http://apcs.cold.rocks

More information

Lecture 07: Object Encapsulation & References AITI Nigeria Summer 2012 University of Lagos.

Lecture 07: Object Encapsulation & References AITI Nigeria Summer 2012 University of Lagos. Accelerating Information Technology Innovation http://aiti.mit.edu Lecture 07: Object Encapsulation & References AITI Nigeria Summer 2012 University of Lagos. Data Field Encapsulation Sometimes we want

More information

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and Classes CS 251 Intermediate Programming Methods and Classes Brooke Chenoweth University of New Mexico Fall 2018 Methods An operation that can be performed on an object Has return type and parameters Method with

More information

CS 251 Intermediate Programming Methods and More

CS 251 Intermediate Programming Methods and More CS 251 Intermediate Programming Methods and More Brooke Chenoweth University of New Mexico Spring 2018 Methods An operation that can be performed on an object Has return type and parameters Method with

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

Introduction to Computer Science Unit 2. Exercises

Introduction to Computer Science Unit 2. Exercises Introduction to Computer Science Unit 2. Exercises Note: Curly brackets { are optional if there is only one statement associated with the if (or ) statement. 1. If the user enters 82, what is 2. If the

More information

University of Massachusetts Amherst, Electrical and Computer Engineering

University of Massachusetts Amherst, Electrical and Computer Engineering University of Massachusetts Amherst, Electrical and Computer Engineering ECE 122 Midterm Exam 1 Makeup Answer key March 2, 2018 Instructions: Closed book, Calculators allowed; Duration:120 minutes; Write

More information

CS 101 Spring 2007 Midterm 2 Name: ID:

CS 101 Spring 2007 Midterm 2 Name:  ID: You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure

More information

Lecture 13 & 14. Single Dimensional Arrays. Dr. Martin O Connor CA166

Lecture 13 & 14. Single Dimensional Arrays. Dr. Martin O Connor CA166 Lecture 13 & 14 Single Dimensional Arrays Dr. Martin O Connor CA166 www.computing.dcu.ie/~moconnor Table of Contents Declaring and Instantiating Arrays Accessing Array Elements Writing Methods that Process

More information

Chapter Seven: Arrays and Array Lists. Chapter Goals

Chapter Seven: Arrays and Array Lists. Chapter Goals Chapter Seven: Arrays and Array Lists Chapter Goals To become familiar with using arrays and array lists To learn about wrapper classes, auto-boxing and the generalized for loop To study common array algorithms

More information

CS 101 Fall 2005 Midterm 2 Name: ID:

CS 101 Fall 2005 Midterm 2 Name:  ID: This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts (in particular, the final two questions are worth substantially more than any

More information

Supplementary Test 1

Supplementary Test 1 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 Supplementary Test 1 Question

More information

CSEN401 Computer Programming Lab. Topics: Introduction and Motivation Recap: Objects and Classes

CSEN401 Computer Programming Lab. Topics: Introduction and Motivation Recap: Objects and Classes CSEN401 Computer Programming Lab Topics: Introduction and Motivation Recap: Objects and Classes Prof. Dr. Slim Abdennadher 16.2.2014 c S. Abdennadher 1 Course Structure Lectures Presentation of topics

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

Object-Oriented Programming and Software Engineering CITS1001 MID-SEMESTER TEST

Object-Oriented Programming and Software Engineering CITS1001 MID-SEMESTER TEST Object-Oriented Programming and Software Engineering School of Computer Science & Software Engineering The University of Western Australia CITS1001 MID-SEMESTER TEST Semester 1, 2013 CITS1001 This Paper

More information

Implementing Classes

Implementing Classes Implementing Classes Advanced Programming ICOM 4015 Lecture 3 Reading: Java Concepts Chapter 3 Fall 2006 Slides adapted from Java Concepts companion slides 1 Chapter Goals To become familiar with the process

More information

University of Palestine. Mid Exam Total Grade: 100

University of Palestine. Mid Exam Total Grade: 100 First Question No. of Branches (5) A) Choose the correct answer: 1. If we type: system.out.println( a ); in the main() method, what will be the result? int a=12; //in the global space... void f() { int

More information

x++ vs. ++x x=y++ x=++y x=0; a=++x; b=x++; What are the values of a, b, and x?

x++ vs. ++x x=y++ x=++y x=0; a=++x; b=x++; What are the values of a, b, and x? x++ vs. ++x x=y++ x=++y x=0; a=++x; b=x++; What are the values of a, b, and x? x++ vs. ++x public class Plus{ public static void main(string []args){ int x=0; int a=++x; System.out.println(x); System.out.println(a);

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

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer Computing Science 114 Solutions to Midterm Examination Tuesday October 19, 2004 INSTRUCTOR: I E LEONARD TIME: 50 MINUTES In Questions 1 20, Circle EXACTLY ONE choice as the best answer 1 [2 pts] What company

More information

STUDENT LESSON A5 Designing and Using Classes

STUDENT LESSON A5 Designing and Using Classes STUDENT LESSON A5 Designing and Using Classes 1 STUDENT LESSON A5 Designing and Using Classes INTRODUCTION: This lesson discusses how to design your own classes. This can be the most challenging part of

More information

MIDTERM REVIEW. midterminformation.htm

MIDTERM REVIEW.   midterminformation.htm MIDTERM REVIEW http://pages.cpsc.ucalgary.ca/~tamj/233/exams/ midterminformation.htm 1 REMINDER Midterm Time: 7:00pm - 8:15pm on Friday, Mar 1, 2013 Location: ST 148 Cover everything up to the last lecture

More information

Imperative Languages!

Imperative Languages! Imperative Languages! Java is an imperative object-oriented language. What is the difference in the organisation of a program in a procedural and an objectoriented language? 30 class BankAccount { private

More information

CONCORDIA UNIVERSITY Summer 2005 Comp 248 /1 Section AA Introduction to Programming Final Examination/A

CONCORDIA UNIVERSITY Summer 2005 Comp 248 /1 Section AA Introduction to Programming Final Examination/A NAME: ID: CONCORDIA UNIVERSITY Summer 2005 Comp 248 /1 Section AA Introduction to Programming Final Examination/A Instructor: N. Acemian Monday June 27, 2005 Duration: 3 hours INSTRUCTIONS: - Answer all

More information

Introduction to Classes and Objects

Introduction to Classes and Objects 3 Nothing can have value without being an object of utility. Karl Marx Your public servants serve you right. Adlai E. Stevenson Knowing how to answer one who speaks, To reply to one who sends a message.

More information

Computer Programming, I. Laboratory Manual. Final Exam Solution

Computer Programming, I. Laboratory Manual. Final Exam Solution Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Final Exam Solution

More information

Repetition CSC 121 Fall 2014 Howard Rosenthal

Repetition CSC 121 Fall 2014 Howard Rosenthal Repetition CSC 121 Fall 2014 Howard Rosenthal Lesson Goals Learn the following three repetition methods, their similarities and differences, and how to avoid common errors when using them: while do-while

More information

CS212 Midterm. 1. Read the following code fragments and answer the questions.

CS212 Midterm. 1. Read the following code fragments and answer the questions. CS1 Midterm 1. Read the following code fragments and answer the questions. (a) public void displayabsx(int x) { if (x > 0) { System.out.println(x); return; else { System.out.println(-x); return; System.out.println("Done");

More information

Java Simple Data Types

Java Simple Data Types Intro to Java Unit 1 Multiple Choice Test Key Java Simple Data Types This Test Is a KEY DO NOT WRITE ON THIS TEST This test includes program segments, which are not complete programs. Answer such questions

More information

Java Assignment 3: Loop Practice Ver 3.0 Last Updated: 12/1/2015 8:57 AM

Java Assignment 3: Loop Practice Ver 3.0 Last Updated: 12/1/2015 8:57 AM Java Assignment 3: Loop Practice Ver 3.0 Last Updated: 12/1/2015 8:57 AM Let s get some practice creating programs that repeat commands inside of a loop in order to accomplish a particular task. You may

More information

Quarter 1 Practice Exam

Quarter 1 Practice Exam University of Chicago Laboratory Schools Advanced Placement Computer Science Quarter 1 Practice Exam Baker Franke 2005 APCS - 12/10/08 :: 1 of 8 1.) (10 percent) Write a segment of code that will produce

More information

Fundamentos de programação

Fundamentos de programação Fundamentos de programação Orientação a Objeto Classes, atributos e métodos Edson Moreno edson.moreno@pucrs.br http://www.inf.pucrs.br/~emoreno Contents Object-Oriented Programming Implementing a Simple

More information

Midterm Examination (MTA)

Midterm Examination (MTA) M105: Introduction to Programming with Java Midterm Examination (MTA) Spring 2013 / 2014 Question One: [6 marks] Choose the correct answer and write it on the external answer booklet. 1. Compilers and

More information

Practice problem on defining and using Class types. Part 4.

Practice problem on defining and using Class types. Part 4. CS180 Programming Fundamentals Practice problem on defining and using Class types. Part 4. Implementing object associations: Applications typically consist of collections of objects of different related

More information

(b) This is a valid identifier in Java: _T_R-U_E_. (c) This is a valid identifier in Java: _F_A_L_$_E_

(b) This is a valid identifier in Java: _T_R-U_E_. (c) This is a valid identifier in Java: _F_A_L_$_E_ ComS 207: Programming I Midterm 1, Tue. Sep 19, 2006 Student Name: Student ID Number: Recitation Section: 1. True/False Questions (10 x 1p each = 10p) (a) ComS 207 Rocks! (b) This is a valid identifier

More information

Oct Decision Structures cont d

Oct Decision Structures cont d Oct. 29 - Decision Structures cont d Programming Style and the if Statement Even though an if statement usually spans more than one line, it is really one statement. For instance, the following if statements

More information

H212 Introduction to Software Systems Honors

H212 Introduction to Software Systems Honors Introduction to Software Systems Honors Lecture #04: Fall 2015 1/20 Office hours Monday, Wednesday: 10:15 am to 12:00 noon Tuesday, Thursday: 2:00 to 3:45 pm Office: Lindley Hall, Room 401C 2/20 Printing

More information

Introduction to Computer Science Unit 2. Notes

Introduction to Computer Science Unit 2. Notes Introduction to Computer Science Unit 2. Notes Name: Objectives: By the completion of this packet, students should be able to describe the difference between.java and.class files and the JVM. create and

More information

EXAM Computer Science 1 Part 1

EXAM Computer Science 1 Part 1 Maastricht University Faculty of Humanities and Science Department of Knowledge Engineering EXAM Computer Science 1 Part 1 Block 1.1: Computer Science 1 Code: KEN1120 Examiner: Kurt Driessens Date: Januari

More information

CSCI 1226 Sample Midterm Exam

CSCI 1226 Sample Midterm Exam CSCI 1226 Test #1 February 2017 General Instructions CSCI 1226 Sample Midterm Exam (A bit long since it combines parts of three earlier tests) Read and follow all directions carefully. Name: Student #:

More information

JAVA OPERATORS GENERAL

JAVA OPERATORS GENERAL JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue General Loops in Java Look at other loop constructions Very common while loop: do a loop a fixed number of times (MAX in the example) int

More information

CSE 142, Spring 2009, Sample Final Exam #2. Good luck!

CSE 142, Spring 2009, Sample Final Exam #2. Good luck! CSE 142, Spring 2009, Sample Final Exam #2 Name: Section: Student ID #: TA: Rules: You have 110 minutes to complete this exam. You will receive a deduction if you keep working after the instructor calls

More information

What will this print?

What will this print? class UselessObject{ What will this print? int evennumber; int oddnumber; public int getsum(){ int evennumber = 5; return evennumber + oddnumber; public static void main(string[] args){ UselessObject a

More information

CMPSCI 187 Midterm 1 (Feb 17, 2016)

CMPSCI 187 Midterm 1 (Feb 17, 2016) CMPSCI 187 Midterm 1 (Feb 17, 2016) Instructions: This is a closed book, closed notes exam. You have 120 minutes to complete the exam. The exam has 10 pages printed on double sides. Be sure to check both

More information

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 7, Name:

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 7, Name: CSC 1051 Algorithms and Data Structures I Midterm Examination October 7, 2013 Name: Question Value Score 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 10 TOTAL 100 Please answer questions in the spaces

More information

INTRODUCTION TO SOFTWARE SYSTEMS (COMP1110/COMP1140/COMP1510/COMP6710)

INTRODUCTION TO SOFTWARE SYSTEMS (COMP1110/COMP1140/COMP1510/COMP6710) Important notice: This document is a sample exam. The final exam will differ from this exam in numerous ways. The purpose of this sample exam is to provide students with access to an exam written in a

More information

if (x == 0); System.out.println( x=0 ); if (x = 0) System.out.println( x=0 );

if (x == 0); System.out.println( x=0 ); if (x = 0) System.out.println( x=0 ); Sample Final Exam 1. Evaluate each of the following expressions and show the result and data type of each: Expression Value Data Type 14 % 5 1 / 2 + 1 / 3 + 1 / 4 4.0 / 2.0 Math.pow(2.0, 3.0) (double)(2

More information

COMP-202. Objects, Part III. COMP Objects Part III, 2013 Jörg Kienzle and others

COMP-202. Objects, Part III. COMP Objects Part III, 2013 Jörg Kienzle and others COMP-202 Objects, Part III Lecture Outline Static Member Variables Parameter Passing Scopes Encapsulation Overloaded Methods Foundations of Object-Orientation 2 Static Member Variables So far, member variables

More information

COE 212 Engineering Programming. Welcome to Exam I Tuesday November 11, 2014

COE 212 Engineering Programming. Welcome to Exam I Tuesday November 11, 2014 1 COE 212 Engineering Programming Welcome to Exam I Tuesday November 11, 2014 Instructors: Dr. Bachir Habib Dr. George Sakr Dr. Joe Tekli Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam

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

Java Programming Language. 0 A history

Java Programming Language. 0 A history Java Programming Language 0 A history How java works What you ll do in Java JVM API Java Features 0Platform Independence. 0Object Oriented. 0Compiler/Interpreter 0 Good Performance 0Robust. 0Security 0

More information

Computer Science II Data Structures

Computer Science II Data Structures Computer Science II Data Structures Instructor Sukumar Ghosh 201P Maclean Hall Office hours: 10:30 AM 12:00 PM Mondays and Fridays Course Webpage homepage.cs.uiowa.edu/~ghosh/2116.html Course Syllabus

More information

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal APCS A Midterm Review You will have a copy of the one page Java Quick Reference sheet. This is the same reference that will be available to you when you take the AP Computer Science exam. 1. n bits can

More information