2000ACExamAnswers

2000ACExamAnswers - QUESTION/ANSWER SHEET CONTINUED...

Info iconThis preview shows pages 1–5. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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 Question/Answer Sheet Candidates 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++; } } } Question/Answer Sheet Candidates 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)); } } today: 3.0 a: 2 b: 30 c: 3.0 day: 32 OK Question/Answer Sheet Candidates 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() { addMouseListener(this); holdPoints = new Vector(); } public void mouseClicked(MouseEvent e){ holdPoints.addElement(e.getPoint()); repaint(); } public void mousePressed(MouseEvent e){} public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void paint(Graphics g){ Point temp; for(int i= 0; i<holdPoints.size(); i++){ Question/Answer Sheet...
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 / 21

2000ACExamAnswers - QUESTION/ANSWER SHEET CONTINUED...

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

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