2009SSExamQuestions

2009SSExamQuestions - CompSci 101 THE UNIVERSITY OF...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CompSci 101 THE UNIVERSITY OF AUCKLAND CONTINUED SUMMER SEMESTER, 2009 Campus: City COMPUTER SCIENCE Principles of Programming (Time Allowed: TWO hours) NOTE: Attempt ALL questions Write your answers in the space provided There is space at the back for answers that overflow the allotted space No calculators are permitted Surname: Forenames: Student ID number: Login name: Q1 (/40) Q3 (/6) Q5 (/9) Q7 (/6) Q2 (/18) Q4 (/7) Q6 (/6) Q8 (/8) TOTAL (/100) Question/Answer Sheet - Page 2 - CompSci 101 ID: ........................................................ CONTINUED Question 1 (40 marks) a) What output is produced by the following code? System.out.println("1. " + (Math.max(4, Math.min(5, 3)))); (2 marks) b) Which statement in the following program causes a compile error (give the line number)? public class Program{ public void start(){ int x = 3; if(x > 1) { int y = x + 3; x = x + y; } System.out.println(x + ", " + y); } } (2 marks) 1 2 3 4 5 6 7 8 9 10 Question/Answer Sheet - Page 3 - CompSci 101 ID: ........................................................ CONTINUED c) What output is produced by the following code? String s1 = "I can do this"; String s2 = "I can too"; int pos1, pos2; pos1 = s1.indexOf("th"); pos2 = s2.indexOf("th"); s2 = s1.substring(pos1); System.out.println(pos1 + ", " + pos2 + ", " + s2); (2 marks) d) What output is produced by the following code? Point pt1 = new Point(3, 2); pt1.x = pt1.y; pt1.y = pt1.x; System.out.println(pt1.x + ", " + pt1.y); (2 marks) Question/Answer Sheet - Page 4 - CompSci 101 ID: ........................................................ CONTINUED e) What output is produced by the following code? Point pt1, pt2; pt1 = new Point(5, 15); pt2 = new Point(10, 25); pt2 = pt1; pt1 = new Point(pt2); System.out.println("1. " + pt1.x + ", " + pt2.x); System.out.println("2. " + (pt1 == pt2)); (2 marks) f) What output is produced by the following code? Point pt1, pt2; pt1 = new Point(5, 15); pt2 = new Point(7, 15); pt1.move(2, 0); System.out.println("1. " + pt1.equals(pt2)); pt2.translate(2, 0); System.out.println("2. " + pt2.x + "," + pt2.y); (2 marks) Question/Answer Sheet - Page 5 - CompSci 101 ID: ........................................................ CONTINUED g) What output is produced by the following code? Rectangle rect1 = new Rectangle(10, 20, 30, 40); Rectangle rect2 = new Rectangle(20, 30, 10, 10); System.out.println("1. " + rect1.intersects(rect2)); Point pt2 = new Point(70, 10); System.out.println("2. " + rect1.contains(pt2)); (2 marks) h) What output is produced by the following program? import java.awt.*; public class Program { public void start() { Rectangle r = new Rectangle(10, 20, 30, 40); questionH(r); System.out.println("1. " + r.x + ", " + r.y + ", " + r.width + ", " + r.height); } private void questionH(Rectangle rect) { rect.x = 33; rect.width = 15; } } (2 marks) Question/Answer Sheet - Page 6 - CompSci 101 ID: ...........................................................
View Full Document

This note was uploaded on 03/01/2012 for the course COMPSCI 101 taught by Professor Adrianaferraro during the Summer '12 term at Auckland.

Page1 / 29

2009SSExamQuestions - CompSci 101 THE UNIVERSITY OF...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online