{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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 Document Right 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 Ann Sato: 9723 Card: 451 Doors 101,222 Mary Pin: 9561 Card: 452 Doors 301,402 Question 5 (8 marks): i) value: 0 value: 4 value: 6 Final value: 6 ii) 1. X*X 2. X* 3. X 4.
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.

{[ snackBarMessage ]}