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

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

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

MID-SEMESTER TEST 2014

int[] a; a = new int[8]; a[0] = 1; a[1] = 1; for (int i = 2; i < 8; i++) a[i] = a[i-1] - a[i-2];

int b = 2; for (int a = 0; a < 10 b < 20; a++) { a = a + b; b = b + a; }

SEMESTER 1, 2011 EXAMINATIONS. CITS1200 Java Programming FAMILY NAME: GIVEN NAMES:

Object-oriented Programming and Software Engineering CITS1001. Multiple-choice Mid-semester Test

1st Semester Examinations CITS1001 3

ENGR 2710U Midterm Exam UOIT SOLUTION SHEET

THE UNIVERSITY OF WESTERN AUSTRALIA

Java Simple Data Types

Key Java Simple Data Types

Java Simple Data Types

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

int a; int b = 3; for (a = 0; a < 8 b < 20; a++) {a = a + b; b = b + a;}

Objects and Classes Lecture 2

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

VARIABLES AND TYPES CITS1001

CSSE SEMESTER 1, 2017 EXAMINATIONS. CITS1001 Object-oriented Programming and Software Engineering FAMILY NAME: GIVEN NAMES:

Understanding class definitions

Ticket Machine Project(s)

PROGRAMMING FUNDAMENTALS

EXPRESSIONS AND ASSIGNMENT CITS1001

Mutating Object State and Implementing Equality

You will not be tested on JUnit or the Eclipse debugger. The exam does not cover interfaces.

INSTRUCTIONS TO CANDIDATES

APCS Semester #1 Final Exam Practice Problems

You must bring your ID to the exam.

School of Computer Science & Software Engineering SEMESTER 2, 2008 EXAMINATIONS 2008 JAVA PROGRAMMING 1200 (CITS1200)

THE UNIVERSITY OF WESTERN AUSTRALIA

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods

Tokens, Expressions and Control Structures

CSE 142, Autumn 2010 Final Exam Wednesday, December 15, Name:

CSC 222: Object-Oriented Programming. Fall 2015

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

Arrays and Array Lists

Computer Science E-119 Fall Problem Set 1. Due before lecture on Wednesday, September 26

Object-oriented basics. Object Class vs object Inheritance Overloading Interface

Today s Agenda. Quick Review

UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED

Imperative Languages!

Defining Classes. Chap 1 introduced many concepts informally, in this chapter we will be more formal in defining

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

CS 231 Data Structures and Algorithms, Fall 2016

public class TicketMachine Inner part omitted. public class ClassName Fields Constructors Methods

UNDERSTANDING CLASS DEFINITIONS CITS1001

CSE 143 SAMPLE MIDTERM

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

Section 003 Fall CS 170 Exam 2. Name (print): Instructions:

CS 302: Introduction to Programming in Java. Lecture 15

CSC 111, Test 1 (Fall 2009)

SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 1 EXAMINATIONS 2015/2016 CI101 / CI177. Programming

Comp2310 & Comp6310 Systems, Networks and Concurrency

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

COE318 Lecture Notes Week 10 (Nov 7, 2011)

CSE 332 Winter 2018 Final Exam (closed book, closed notes, no calculators)

Prelim 1. CS 2110, October 1, 2015, 5:30 PM Total Question Name True Short Testing Strings Recursion

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Building Java Programs

Computer Science and Software Engineering SEMESTER 1, 2016 EXAMINATIONS. CITS1001 Object-oriented Programming and Software Engineering

ITI Introduction to Computing II

ITI Introduction to Computing II

Exercise 6 Multiple Inheritance, Multiple Dispatch and Linearization November 3, 2017

Inheritance: Definition

CS 307 Midterm 2 Fall 2009

Use the scantron sheet to enter the answer to questions (pages 1-6)

Largest Online Community of VU Students

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2013

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

A Sophomoric Introduction to Shared-Memory Parallelism and Concurrency Lecture 4 Shared-Memory Concurrency & Mutual Exclusion

Understanding class definitions. Looking inside classes (based on lecture slides by Barnes and Kölling)

CS 101 Exam 2 Spring Id Name

Introduction to Programming Using Java (98-388)

CSC 222: Object-Oriented Programming. Fall 2017

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

Introduction to Computer Science Midterm 3 Fall, Points

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

CISC 1600 Lecture 3.1 Introduction to Processing

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

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.

CS112 Lecture: Defining Instantiable Classes

NATIONAL UNIVERSITY OF SINGAPORE

JAVA OPERATORS GENERAL

Programmazione di sistemi multicore

Basic Object-Oriented Concepts. 5-Oct-17

Practice Midterm 1. Problem Points Score TOTAL 50

index.pdf January 21,

Chapter Seven: Arrays and Array Lists. Chapter Goals

CSCI 161 Introduction to Computer Science

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

NATIONAL UNIVERSITY OF SINGAPORE

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

Announcements. Last modified: Fri Sep 8 00:59: CS61B: Lecture #7 1

CIS 110 Introduction to Computer Programming Summer 2018 Final. Recitation # (e.g., 201):

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring Instructions:

CS 307 Midterm 1 Spring 2009

Lecture 10: Interfaces

ITI Introduction to Computing II

Introduction to Inheritance

Transcription:

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 Contains: 12 Pages 15 Questions Time allowed : FORTY (40) MINUTES Marks for this paper total 15. Candidates should answer ALL questions on the machine readable answer sheet provided.

1. Consider the following method (with line numbers): 1. public boolean justamethod(string name, Int mark){ 2. boolean n = false; 3. if ( name.equals("anon") { 4. return n; 5. else { 6. return (mark*2); 7. 8. Compiler errors would be reported for: a. line 1 b. lines 1 and 6 c. lines 1, 4 and 6 d. lines 1, 3 and 6 e. lines 1 and 3 2. The Picture class of the shapes project studied in lectures and labs includes the declaration private Triangle roof; In the statement roof.movehorizontal(20); what does movehorizontal refer to? a. It is a field belonging to the class Triangle. b. It is a field belonging to the object roof. c. It is a method belonging to the object roof. d. It is a method belonging to the class Triangle. e. It is a method belonging to the class Picture. 3

3. What are the values in each of the variables after the following code has been executed: int x = 7; int y = 5; int z = 0; z = x; x = y; y = z; a. x is 7, y is 5, z is 0 b. x is 5, y is 0, z is 7 c. x is 5, y is 5, z is 0 d. x is 5, y is 7, z is 7 e. None of the above. 4. The variable int runtime contains the running time of a movie in minutes. You wish to convert it to the normal hours-and-minutes notation (e.g. 133 minutes = 2 hours and 13 minutes). Which piece of code is correct? a. int hours = runtime / 60; int minutes = (runtime - hours * 60) / 60; b. int hours = runtime % 60; int minutes = runtime; c. int minutes = runtime % 60; int hours = runtime / 60; d. int minutes = runtime % 60; int hours = runtime - 60 * minutes; e. int hours = runtime - 60; int minutes = runtime / 60; 4

5. Consider the following block of code, where variables a, b and c each store integer values: if (a > b) { if (b > c) { System.out.println(c); else { System.out.println(b); else if (a > c) { System.out.println(c); else { System.out.println(a); Which one of the following initial values for the variables will cause the value in variable b to be printed? a. a is 2, b is 1, c is 1 b. a is 1, b is 1, c is 2 c. a is 3, b is 2, c is 1 d. a is 1, b is 3, c is 2 e. a is 1, b is 2, c is 3 6. We have two monkeys, a and b, and the parameter variables asmile and bsmile indicate if each is smiling. We are in trouble if they are both smiling or if neither of them is smiling. Which of the following statements returns true if and only if we are in trouble. a. return ((asmile == bsmile) (asmile!= bsmile)); b. return ((asmile && bsmile) (!asmile!bsmile)); c. return (asmile bsmile); d. return (asmile && bsmile); e. return (asmile == bsmile); 5

7. The following method from the MarksAnalyser class used in labs is intended to count the number of marks that are in the range low to high (inclusive), but it is missing one line of code. public int countnuminrange(int low, int high) { int count=0; for (StudentMark sm : marks) { //missing line of code here { count++; return count; What code should replace the comment line (//missing line of code here) so that the method returns the correct result? a. if (low < sm.getmark()) b. if (high > sm.getmark()) c. if ((low <= sm.getmark()) (sm.getmark() <= high)) d. if ((low <= sm.getmark()) && (sm.getmark() <= high)) e. if (low < high) 6

8. What value does mystery(100) return? public int mystery(int k){ while ( k>10 ) { k = k/2; return k; a. 2 b. 6 c. 100 d. 12 e. 5 9. What value does somemethod(6) return? public int somemethod(int n) { if (n > 1) { int[] a = new int[n]; a[0] = 1; a[1] = 1; for (int i = 2; i < n; i++) { a[i] = a[i-1] + a[i-2]; return a[n-1]; else { return -1; a. 1 b. 2 c. 5 d. 8 e. 13 7

10. Consider the following class definition public class BankAccount { private int balance; public BankAccount(int balance) { this.balance = balance; public void deposit(int amount) { balance = balance + amount; public void withdraw(int amount) { balance = balance - amount; public int getbalance() { return balance; public void bankdemo() { BankAccount b1 = new BankAccount(1000); BankAccount b2 = new BankAccount(500); b1.deposit(1500); b2.withdraw(200); b1.deposit(b2.getbalance()); System.out.println(b1.getBalance() + " and " + b2.getbalance()); What would be printed to the terminal screen when the method bankdemo() is executed? a. 1700 and 1700 b. 2500 and 1300 c. 2800 and 300 d. 3100 and 3100 e. 3500 and 3500 8

11. The following implementation of the discount method of the TicketMachine class studied in lectures and labs contains an error. public void discount(int amount) { if ((0 < amount) (amount > price)) { price = price - amount; else { System.out.println("Discount is too large"); Supposing you have created a JUnit test object ticket200 = new TicketMachine(200); Which of the following JUnit test cases will fail, so alerting you to the error. a. ticket200.discount(50); assertequals(150,ticket200.getprice()); b. ticket200.discount(25); assertequals(125,ticket200.getprice()); c. ticket200.discount(-10); assertequals(200,ticket200.getprice()); d. ticket200.discount(200); assertequals(200,ticket200.getprice()); e. ticket200.discount(250); assertequals(200,ticket200.getprice()); Comment on the answer: The given code would pass the tests in a and c, and fail those in b,d,e. Assuming the the correct implementation uses if ((0 < amount) && (amount <= price))... then the correct code would pass the tests in a, c and e, and fail those in b and d. In this case, only option e fails with the given code but would pass with the correct code, and so e is the best choice for a test to fail, so alerting you to the error. This correctness assumption allows a 100% discount, but not more than 100% and discount must be greater than 0% (or it would not be a discount). 9

12. The source code for a class a. must explicitly define exactly one constructor. b. must explicitly define at least one constructor. c. must explicitly define at most one constructor. d. can explicitly define zero, one or more constructors. e. should never contain any explicitly defined constructors. 13. The declaration private Circle sun; a. creates a field variable sun referring to a newly created Circle object, which by default has the colour yellow. b. creates a field variable sun with initial value null. c. creates a field variable sun that is drawn in the middle of the canvas. d. creates a field variable sun with an unspecified initial value. e. causes a syntax error, as it is not permitted to declare a variable of reference type without creating the associated object. 14. Which of these statements apply to a large program written in good object-oriented style? 1. Objects are capable of many complex tasks and communicate as little as possible during runtime. 2. Complex problems are solved by the co-operation of objects from several different classes. 3. Each class of objects provides a narrow range of well-defined services. 4. In carrying out their tasks, objects act as clients or servers but never both, during runtime. a. 1 and 2 only b. 2 and 3 only c. 3 and 4 only d. 1 and 4 only e. 2, 3 and 4 only 10

15. What sort of variables are used to store the state of an individual object? a. Local variables. b. Field variables. c. Reference variables. d. Parameter variables. e. Method variables. 11