2009S1ExamQuestions

2009S1ExamQuestions - CompSci 101 THE UNIVERSITY OF...

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

View Full Document Right Arrow Icon
CompSci 101 THE UNIVERSITY OF AUCKLAND CONTINUED FIRST 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) Q4 (/5) Q7 (/5) Q10 (/8) Q2 (/7) Q5 (/7) Q8 (/7) Q3 (/7) Q6 (/7) Q9 (/7) TOTAL (/100)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Question/Answer Sheet - Page 2 - CompSci 101 ID: . ....................................................... CONTINUED Question 1 (40 marks) a) Write ALL the possible numbers which could be printed by the following statement. System.out.print((int)(Math.random() * 4 + 2)); (2 marks) b) What is printed by the following code? int a = 5; int b = a / 3; double c = a / 4; a = a % 3; System.out.println(a + " " + b + " " + c); (2 marks)
Background image of page 2
Question/Answer Sheet - Page 3 - CompSci 101 ID: . ....................................................... CONTINUED c) Complete the output produced by the following code. public class Program { public void start() { Point point1 = new Point(20, 15); System.out.println("1. " + point1.x + "," + point1.y); methodC(point1); System.out.println("2. " + point1.x + "," + point1.y); } private void methodC(Point pt2) { pt2.x = 5; pt2.y = 3; pt2 = new Point(2, 4); } } 1. 2. (2 marks) d) Complete the output produced by the following program. public class Program { public void start() { Point point1 = new Point(20, 15); System.out.println("1. " + point1.x + "," + point1.y); methodD(point1); System.out.println("2. " + point1.x + "," + point1.y); } private void methodD(Point pt2) { pt2 = new Point(2, 4); pt2.x = 5; pt2.y = 3; } } 1. 2. (2 marks)
Background image of page 3

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

View Full DocumentRight Arrow Icon
Question/Answer Sheet - Page 4 - CompSci 101 ID: . ....................................................... CONTINUED e) Complete the header of the following method. private methodE ( Rectangle , ) { if (rect.contains(pt)) { return true; } return false; } (2 marks) f) Complete the header of the following method. private methodF ( ) { int[] b = new int[numbers.length]; int limit = 100; for (int i=0; i<numbers.length; i++) { if (numbers[i] < limit) { b[i] = numbers[i]; } else { b[i] = -1; } } return b; } (2 marks)
Background image of page 4
Question/Answer Sheet - Page 5 - CompSci 101 ID: . ....................................................... CONTINUED g) Complete the output produced by the following code. int xPos = 20; int yPos = 15; int width = 50; int height = 8; Rectangle rect1, rect2, rect3; rect1 = new Rectangle(10, 11, 30, 7); rect2 = new Rectangle(xPos , yPos, width, height); rect3 = new Rectangle(rect1); rect3.x = rect1.y; rect1.y = rect2.height; System.out.println("1. " + rect1.x + "," + rect1.y + "," + rect1.width + "," + rect1.height); System.out.println("2. " + rect3.x + "," + rect3.y + "," + rect3.width + "," + rect3.height); 1.
Background image of page 5

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

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

Page1 / 30

2009S1ExamQuestions - CompSci 101 THE UNIVERSITY OF...

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

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