{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This preview shows pages 1–7. 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
Image of page 1

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

View Full Document Right 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++; } } }
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)); } } today: 3.0 a: 2 b: 30 c: 3.0 day: 32 OK
Image of page 3

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

View Full Document Right 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() { 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++){
Image of page 4
Question/Answer Sheet Candidate’s Name: _______________ - 5- 415.101AC QUESTION/ANSWER SHEET CONTINUED temp = (Point) holdPoints.elementAt(i); g.fillRect(temp.x, temp.y, SIZE, SIZE); } } }
Image of page 5

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

View Full Document Right Arrow Icon
Question/Answer Sheet Candidate’s Name: _______________ - 6- 415.101AC QUESTION/ANSWER SHEET CONTINUED Question 4 (10 marks) Complete the code for the following Applet. This Applet allows the user to type words into the TextField;
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern