2001FCExamAnswers

2001FCExamAnswers - C ompSci 101 FC THE UNIVERSITY OF...

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

View Full Document Right Arrow Icon
CompSci 101 FC THE UNIVERSITY OF AUCKLAND CONTINUED FIRST SEMESTER, 2001 City Campus COMPUTER SCIENCE Principles of Programming (Time allowed: TWO hours) Surname: Perfect Forenames: Mr. Student ID number: 2001 INSTRUCTIONS: Attempt ALL questions - write your answers in the space provided Marks for each question are shown, and total 100. There is extra space on the last page of the booklet if you need it There is an appendix at the end of this booklet which lists some useful methods and instance variables Calculators are NOT permitted Examiner to complete: Question Mark Question Mark 1 10 (/10) 7 5 (/5) 2 10 (/10) 8 5 (/5) 3 10 (/10) 9 10 (/10) 4 5 (/5) 10 10 (/10) 5 10 (/10) 11 10 (/10) 6 10 (/10) 12 5 (/5) TOTAL: 100 (/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 - Page 2 - CompSci 101 FC SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 1 (10 marks) a) Declare a local variable of type double called rate and assign it the value 3. double rate = 3; (2 marks) b) What is the scope of an instance variable? the entire class (2 marks) c) What does the word “ void ” mean in the following method header? private void printResults(int a, int b) { the method does not return any value (2 marks) d) Write a Java statement (or statements) to print out the length of the String stored at element 0 of a Vector called v . String elt = (String)v.elementAt(0); System.out.println(elt.length()); (2 marks) e) Rewrite the following “ while ” loop as a “ for ” loop: int i = 4; while (i < lastHouseNo) { System.out.println(“House No.” + i); i = i + 2; } for (int i = 4; i < lastHouseNo; i += 2) System.out.println("House No. " + i); (2 marks)
Background image of page 2
Question/Answer Sheet - Page 3 - CompSci 101 FC SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 2 (10 marks) You need to complete the paint() method of the following applet: import java.awt.*; import java.applet.*; public class Q2 extends Applet { public void paint(Graphics g) { final int SIZE = 50; g.drawRect(100 - SIZE, 100 - SIZE, 2*SIZE, 2*SIZE); g.drawLine(100-SIZE, 100+SIZE, 100+SIZE, 100-SIZE); } (10 marks) } All of the parameters to the drawing methods you call in paint() must be based on the constant SIZE . When the value of SIZE is 50 the applet should produce the drawing on the left below, where the width of the square that is drawn is exactly half the width of the applet window. The applet window is exactly 200 pixels wide and 200 pixels high: The square that is drawn must always be centred at exactly the middle of the applet window, and must have a line drawn from its bottom left to its top right corner.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
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 / 18

2001FCExamAnswers - C ompSci 101 FC THE UNIVERSITY OF...

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

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