2004FCExamQuestions

2004FCExamQuestions - CompSci 101 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 THE UNIVERSITY OF AUCKLAND CONTINUED First Semester, 2004 Campus: City and Tamaki COMPUTER SCIENCE Principles of Programming (Time allowed: TWO HOURS) Surname: Forenames: Student ID number: Login name (UPI): INSTRUCTIONS: Attempt ALL questions, calculators are NOT permitted There is space at the back for answers that overflow the allotted space Examiner to complete: Question Mark Question Mark 1 (/9) 8 (/11) 2 (/5) 9 (/8) 3 (/5) 10 (/10) 4 (/5) 11 (/6) 5 (/5) 12 (/6) 6 (/10) 13 (/5) 7 (/5) 14 (/10) TOTAL: (/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 SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 1 (9 marks) a) What is printed by the following? System.out.println(2 + 3 * 6 + "7 * 8"); (2 marks) b) What is printed by the following? String s = "How now brown cow?"; System.out.println(s.substring(s.lastIndexOf("ow")-1)); (2 marks) c) Consider the class FishRecord below: public class FishRecord { // instance variables private String type; private int amount; //default constructor public FishRecord() { type = ""; amount = 0; } public FishRecord(String inputString, int inputNum) { type = inputString + " " + inputNum + "\n"; amount = inputNum; } public void addRecord(String inputString, int inputNum) { amount += inputNum; type = type + inputString + " " + inputNum + ",\n"; } public String toString() { return(type + "total: " + amount) ; } }
Background image of page 2
Question/Answer Sheet - Page 3 - CompSci 101 SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED What is the output of the application Q1 which uses FishRecord ? public class Q1 { public static void main(String[] args) { FishRecord record1 = new FishRecord("guppy", 8); System.out.println(record1.toString()); FishRecord record2 = new FishRecord(); record2.addRecord("betta", 5); record2.addRecord("catfish", 10); System.out.println(record2.toString()); } } (5 marks)
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 SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 2 (5 marks) Write a static method called keepUpperCase() which accepts a String as a parameter and returns a new String containing only the characters from the original String which were uppercase. For example, if the following code was executed: System.out.println(keepUpperCase("Hello World")); The result would be: HW The following sections of the Java API might be useful: java.lang Class Character java.lang.Object java.lang.Character public static boolean isUpperCase (char ch) Determines if the specified character is an uppercase character. Parameters:
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 / 30

2004FCExamQuestions - CompSci 101 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