2000ACExamQuestions

2000ACExamQuestions - 415.101AC THE UNIVERSITY OF AUCKLAND...

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

View Full Document Right Arrow Icon
QUESTION/ANSWER SHEET CONTINUED 415.101AC THE UNIVERSITY OF AUCKLAND EXAMINATION FOR BA BSc ETC 2000 COMPUTER SCIENCE Principles of Programming (Time Allowed: TWO hours) S urname (Family name): First Name(s) (Given names): Student ID: NOTE: Attempt ALL questions. Write your answers in the space provided. There is space at the back for answers that overflow the allotted space. Calculators are NOT permitted. Marks for each question are as shown and total 100. The last page of this book includes a number of useful methods and instance variables. Question Marks Possible Marks Q.1 5 Q.2 10 Q.3 9 Q.4 10 Q.5 6 Q.6 10 Q.7 12 Q.8 10 Q.9 6 Q.10 10 Q.11 12 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 Candidate’s Name: _______________ - 2- 415.101AC QUESTION/ANSWER SHEET CONTINUED Question 1 (5 marks) What is the output from this program? public class Q1 { public static void main(String args[]) { int[] myInts = {12, 15, 29, 11}; int chosen = myInts[0]; int i = 1; while (i < myInts.length){ if (i%2 == 0){ chosen = Math.max(myInts[i], chosen); System.out.println("chosen: "+ chosen); } else { chosen = Math.min(myInts[i], chosen); System.out.println("chosen: "+ chosen); } i++; } } }
Background image of page 2
Question/Answer Sheet Candidate’s Name: _______________ - 3- 415.101AC QUESTION/ANSWER SHEET CONTINUED Question 2 (10 marks) What is the output of the following applet: import java.applet.Applet; public class Question2 extends Applet { int a = 2; int b = 2; double c = 1.5; public void happy(boolean ok) { if (ok) System.out.println("OK"); else System.out.println("Not OK"); } public boolean valentines(int b) { System.out.println("day: " + b); if (a == 2) return ((int)c > a); else return ((int)c < a); } public int today(int a, double b) { b = a * b; c = b; System.out.println("today: " + c); a++; return 10 * a; } public int tomorrow() { int b = a; return b; } public void init() { int day; b = today(a, c); System.out.println("a: " + a); System.out.println("b: " + b); System.out.println("c: " + c); day = tomorrow() + b; happy(valentines(day)); } }
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 Candidate’s Name: _______________ - 4- 415.101AC QUESTION/ANSWER SHEET CONTINUED Question 3 (9 marks) Complete the following Applet. When the Applet first appears there is nothing in the Applet area. Whenever the user clicks on the Applet area a small black square (size 10 pixels) appears in the Applet area; the top left position of the square is where the user clicked. import java.awt.*; import java.applet.*; import java.awt.event.*; import java.util.*; public class Q3 extends Applet implements MouseListener{ static final int SIZE = 10; private Vector holdPoints; public void init() { } public void mouseClicked(MouseEvent e){ } public void mousePressed(MouseEvent e){}
Background image of page 4
Question/Answer Sheet Candidate’s Name: _______________ - 5- 415.101AC QUESTION/ANSWER SHEET CONTINUED public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void paint(Graphics g){ } }
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 / 24

2000ACExamQuestions - 415.101AC THE UNIVERSITY OF AUCKLAND...

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