2001FCExamQuestions

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

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

View Full Document Right Arrow Icon
CompSci 101 FC THE UNIVERSITY OF AUCKLAND FIRST SEMESTER, 2001 City Campus COMPUTER SCIENCE Principles of Programming (Time allowed: TWO hours) Surname: Forenames: Student ID number: 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) 7 (/5) 2 (/10) 8 (/5) 3 (/10) 9 (/10) 4 (/5) 10 (/10) 5 (/10) 11 (/10) 6 (/10) 12 (/5) TOTAL: (/100) CONTINUED
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: . .......................................................... Question 1 (10 marks) a) Declare a local variable of type double called rate and assign it the value 3. (2 marks) b) What is the scope of an instance variable? (2 marks) c) What does the word “ void ” mean in the following method header? private void printResults(int a, int b) { (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 . (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; } (2 marks) CONTINUED
Background image of page 2
Question/Answer Sheet - Page 3 - CompSci 101 FC SURNAME: . ..................................................... FORENAMES: . .......................................................... 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; } (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. The constant SIZE can be used to scale the drawing. For example, if the value of SIZE is changed to 25, the drawing on the right above should be produced. In this drawing, the width of the square is exactly a quarter the width of the applet window. CONTINUED
Background image of page 3

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

View Full DocumentRight Arrow Icon
Question/Answer Sheet - Page 4 - CompSci 101 FC SURNAME: . ..................................................... FORENAMES: . ..........................................................
Background image of page 4
Image of page 5
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 / 20

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

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