{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2001FCExamQuestions

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

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

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

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

View Full Document
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
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

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

View Full Document
Question/Answer Sheet - Page 4 - CompSci 101 FC SURNAME: ...................................................... FORENAMES: ........................................................... Question 3 (10 marks) We wish to provide a commentary to a user based on how well they are progressing in a game of finding a hidden spot. To do this we track the user’s progress for their last guess as well as for their current guess. We define three levels of progress: SAME ; CLOSER ; and FURTHER (represented by integer constants). Then, based on their progress we will give them a comment. The method progressMessage() , detailed below, determines what message will be returned to the user. The parameters lastGuess and thisGuess will only hold values represented by the integer constants SAME , CLOSER , and FURTHER .
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern