2002SCExamQuestions

2002SCExamQuestions - COMPSCI 101 CONTINUED THE UNIVERSITY...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: COMPSCI 101 CONTINUED THE UNIVERSITY OF AUCKLAND SECOND SEMESTER, 2002 Campus: City and Tamaki COMPUTER SCIENCE Principles of Programming (Time allowed: TWO hours) NOTE: Attempt ALL questions. Write your answers in the space provided. There is space at the back for answers that overflow the allotted space There is also a page at the back for rough working. This page will not be marked. No Calculators are permitted Surname Forenames Student ID Login name Question Marks Out of Question 1 (Short answer) 10 Question 2 (Writing methods) 10 Question 3 (Desk-checking methods) 10 Question 4 (Classes) 15 Question 5 (ActionListener, MouseListener) 15 Question 6 (Bresenham's line algorithm) 20 Question 7 (Ethics) 20 Total 100 Candidate's Name:___________________ 2 COMPSCI 101 CONTINUED 1. What is the output shown by each of the following code fragments? (a) System.out.println(2+3+"^2+3^"+2+3); (1 mark) (b) System.out.println(2/4*4.0+"^"+2.0/4*4); (1 mark) (c) int a = 7; int b = 3; if( a % 3 == b % 2 ) System.out.println("Equal"); if( !(a != 3) || !(b == 3) ) System.out.println("Not"); (2 marks) (d) int a = 7; int b = 3; if( a==7 && ( a!=4 && b+4==a) ) System.out.println("And"); if( a==3 || (a==7 && b==4) || (b!=7 || b==7) ) System.out.println("Or"); (2 marks) (e) System.out.println("Before"); for(int i=0; i<0; i++) System.out.println("Test" + i); System.out.println("After"); (1 mark) Candidate's Name:___________________ 3 COMPSCI 101 CONTINUED (f) int a = 4; int b = 5; int c = 6; int d = 7; if( a > b && b > c ) System.out.println("a>c"); else if( (a+d) == (b+c) ){ if( a-b < d-c) if( a == d ) System.out.println("b > c"); else if( a > d ) System.out.println("c > b"); else System.out.println("unknown"); } else System.out.println("Confused yet?"); System.out.println("I am"); (2 marks) (g) int k=0; int i=0; for(i=0; i<3; i++); { System.out.println("Test" + i); if(k == 0) k = 2; else k = 0; System.out.println(k); } (1 mark) Candidate's Name:___________________ 4 COMPSCI 101 CONTINUED 2. Write a method called scramble() which is used to rearrange the letters in a given String . The letters should be rearranged into random order, based on a "key" value which is used as the "seed" for the pseudo-random number generator used by Java. Your method should accept a String and an int as parameters, and should return a String which contains the same letters, but rearranged into random order. If the scramble() method is called on two separate occasions with the same parameters, then the characters will be arranged in the same order on both occasions. All of the letters in the original String should be used (including all spaces and punctuation). Example: Executing the statements: System.out.println( scramble( "Hello", 100 ) ); System.out.println( scramble( "Hello", 200 ) ); System.out.println( scramble( "Have a nice day", 1234 ) ); System.out.println( scramble( "Hello", 100 ) ); would produce the output: Hlloe olelH ie Hd ncyvaeaa Hlloe You should use the Random class in order to select the letters in the same order given the same...
View Full 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 / 24

2002SCExamQuestions - COMPSCI 101 CONTINUED THE UNIVERSITY...

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