2001ACExamAnswers

2001ACExamAnswers - T HE UNIVERSITY OF AUCKLAND SUMMER...

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

View Full Document Right Arrow Icon
THE UNIVERSITY OF AUCKLAND SUMMER SEMESTER, 2001 COMPUTER SCIENCE Principles of Programming EXAM ANSWERS Question 1 (6 marks): i) String[] allStrings = new String[300]; ii) allStrings[9] = "Relax"; iii) len = allStrings[9].length(); Question 2 (15 marks): public void paint( Graphics g ) { int x,y; int size = 4; //initial size of the square g.setColor(Color.blue); for(int i=0; i<upToInArray; i++){ x = thePoints[i].x; y = thePoints[i].y; g.fillRect(x-size/2,y-size/2,size,size); size++; } } public void actionPerformed(ActionEvent e) { for(int i=0; i<upToInArray; i++){ thePoints[i].translate(-2,0); } repaint(); } public void mousePressed(MouseEvent e) { thePoints[upToInArray] = e.getPoint(); upToInArray++; repaint(); }
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 3 (10 marks): private int sumOver(int[][] theInts, int over){ int sum = 0; for (int i=0; i<theInts.length; i++){ for (int j=0; j<theInts[i].length; j++){ if (theInts[i][j] > over){ sum += theInts[i][j]; } } } return sum; } Question 4 (8 marks): Joe Biggs: 9876 Card: 450 Doors 503,702
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the 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 / 4

2001ACExamAnswers - T HE UNIVERSITY OF AUCKLAND SUMMER...

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

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