2002FCExamQuestions

2002FCExamQuestions - COMPSCI 101FC THE UNIVERSITY OF...

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

View Full Document Right Arrow Icon
COMPSCI 101FC THE UNIVERSITY OF AUCKLAND ______________________________________________ EXAMINATION FOR BSc ETC 2002 ______________________________________________ COMPUTER SCIENCE Principles of Programming (Time allowed: TWO hours) NOTE: Attempt ALL questions. Write your answers in the answer book provided at the end of the exam paper. You may detach the answer book from the questions. Marks for each question are shown and total 100 . Page 11 of this book includes a number of useful methods and instance variables. There are blank pages at the back of the book to use, if required, for any rough working. Program style will be taken into account in marking; you should follow the style guidelines taught throughout the course. You will get partial marks if you express parts of a program in precise pseudocode rather than Java. Unless otherwise stated your programs do NOT need to deal with invalid inputs. When you are asked to write code you do NOT have to include Javadoc comments. 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
- 2 - COMPSCI 101FC Question 1 (5 marks) a) What is ONE possible output from the following statement? System.out.println("Output: " + (int)(Math.random()*10) + 5); (1 mark) b) What is the output of the following code segment? int i1 = 2 + 2 / (2 * 2) - 2; int i2 = 2 / 2 + 2 * 2 - 2; System.out.println(i1 + "." + i2); (1 mark) c) Circle the THREE places in the following code where there are syntax errors, preventing the code from compiling: public class Question1 { public void go { Sytem.out.println("Good luck for the exam"); int mark = 50 * 2; System.out.println(I hope your mark is " + mark); } } (3 marks) Question 2 (12 marks) For this question you need to complete the Q2 class, which draws a circle in the middle of the window. Initially, the radius of the circle is 20 pixels and the centre of the circle is drawn at position (100, 100). The window also contains a TextField and two Button s, as the screenshot below shows: The user can change the size of the circle, either by entering a new radius in the TextField , or by clicking on the Button s labelled " Smaller " and " Bigger ". For example, the user might change the radius of the circle to 47, by entering the value 47 in the TextField , as shown in the screen shot below: CONTINUED
Background image of page 2
- 3 - COMPSCI 101FC If the Button labelled " Smaller " is pressed, the radius of the circle should decrease by 5 pixels. If the Button labelled " Bigger " is pressed, the radius of the circle should increase by 5 pixels. For example, the screen shot below shows the program from above just after the " Smaller " Button has been pressed. Notice that the radius of the circle is now 42 pixels. Also notice that the value in the TextField has changed. The TextField should always display the current radius of the circle. There is no upper limit to the size of the circle (if it gets too big, it just won't be visible on the screen), however, the radius of the circle should never be less than 5. If the user enters a value less than 5 in the TextField , you should change the value to 5 and make sure the circle is drawn with a radius of 5 pixels. If the " Smaller " Button is pressed, and the radius of the circle would become less than 5, it should be set equal to 5.
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.

Page1 / 12

2002FCExamQuestions - COMPSCI 101FC 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