3 Pages

2008S2ExamQuestions

Course: COMPSCI 101, Summer 2012
School: University of Auckland
Rating:
 
 
 
 
 

Word Count: 2289

Document Preview

101 THE COMPSCI UNIVERSITY OF AUCKLAND SECOND SEMESTER, 2008 Campus: City 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 No calculators are permitted Surname: Forenames: Student ID number: Login name: Q1 Q4 (/32) Q2 Q7 (/7) Q5 (/11) Q3...

Register Now

Unformatted Document Excerpt

Coursehero >> Other International >> University of Auckland >> COMPSCI 101

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
101 THE COMPSCI UNIVERSITY OF AUCKLAND SECOND SEMESTER, 2008 Campus: City 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 No calculators are permitted Surname: Forenames: Student ID number: Login name: Q1 Q4 (/32) Q2 Q7 (/7) Q5 (/11) Q3 (/7) Q8 (/7) Q6 (/6) Q10 Q11 (/7) Q9 (/7) (/6) (/7) Total (/3) /100 CONTINUED -2Question/Answer Sheet COMPSCI 101 I D: ..................................................................... Question 1 (32 marks) a) What is the output produced by the following code? System.out.println("Min is: " + Math.min(1, Math.min(0, -1))); (2 marks) b) What is the output produced by the following code? int value = 13; System.out.println( ! (6 < value) ); (2 marks) c) What is the output produced by the following code? int i = 5; int[] numbers = {4, 2, -7, 5, 1, 6, 3}; System.out.println(numbers[i] + numbers[i+1]); (2 marks) CONTINUED -3Question/Answer Sheet COMPSCI 101 I D: ..................................................................... d) What is the output produced by the following code? String name = "intuitive"; name = name.substring(2); int position = name.indexOf('i'); System.out.println(name.substring(0, position + 1)); (2 marks) e) What is the output produced by the following code? double d = 23.7, e = 3.1; System.out.println((int)(Math.round(d - e))); (2 marks) f) Complete the output which is produced by the following code. Point p1 = new Point(4, 6); Point p2 = new Point(3, 5); p1.move(10, 4); p2.translate(10, 4); System.out.println("1: " + p1.x + ", " + p1.y); System.out.println("2: " + p2.x + ", " + p2.y); 1: 2: (2 marks) CONTINUED -4Question/Answer Sheet COMPSCI 101 I D: ..................................................................... g) Complete the output which is produced by the following code. Point p1 = new Point(4, 6); Point p2 = new Point(4, 6); Point p3 = p2; p2 = new Point(p3.x, p3.y); System.out.println("1: " + p1.equals(p2)); System.out.println("2: " + (p2 == p3)); 1: 2: (2 marks) h) What is the output produced by the following code? Rectangle rect = new Rectangle(20, 30, 50, 40); Point p = new Point(rect.x + 5, rect.y + 2); if (rect.contains(p)) { System.out.println("Yes"); } else { System.out.println("No"); } (2 marks) CONTINUED -5Question/Answer Sheet i) COMPSCI 101 I D: ..................................................................... Complete the following code so that it produces the output: No Rectangle rect1 = new Rectangle(20, 30, 50, 40); Rectangle rect2 = new Rectangle(10, 20, , ); if (rect1.intersects(rect2)) { System.out.println("Yes"); } else { System.out.println("No"); } (2 marks) j) What is the output when the start() method below is executed? public void start() { Point p1 = new Point(3, 5); doSomething(p1); System.out.println("1: " + p1.x + ", " + p1.y); } private void doSomething(Point p) { p.x = p.x + 10; System.out.println("2: " + p.x + ", " + p.y); } (2 marks) CONTINUED -6Question/Answer Sheet COMPSCI 101 I D: ..................................................................... k) Declare a constant for the Greek letter pi and assign to it the value 3.14159. (2 marks) l) Write a while loop that adds together the first n positive integers, i.e., 1 + 2 + 3 + ... + n and stores the result in the variable, sum. int sum = 0; (2 marks) m) Rewrite the following while loop into an equivalent for loop. int i = 0; while (i < exp) { total = total * base; i++; } (2 marks) CONTINUED -7Question/Answer Sheet COMPSCI 101 I D: ..................................................................... n) Declare a String array variable, months. (2 marks) o) Construct the months array declared in n) above, so that it is large enough to hold the names of all the months, one name per element. months = (2 marks) p) Why don't you need to worry about aliasing when dealing with String objects? (2 marks) CONTINUED -8Question/Answer Sheet COMPSCI 101 I D: ..................................................................... Question 2 (11 marks): Complete each of the methods below as specified in the comment preceding each method. a) //method to return an int twice as large as n private int twice(int n){ } (2 marks) b) //method to decide whether n1 and n2 are in ascending //order (or of equal value) private boolean areInOrder(int n1, int n2){ } (2 marks) c) //method to tell whether one String, s1, has the same //last character as another String, s2 private boolean sameFinish(String s1, String s2){ int lastS1 = s1.length()-1; int lastS2 = s2.length()-1; } (3 marks) CONTINUED -9Question/Answer Sheet COMPSCI 101 I D: ..................................................................... d) //method to replicate a String, s, the number of //times given by the int, n. For example //reiterate("ho", 3) should return "hohoho" private String reiterate(String s, int n){ result = ""; return result; } (4 marks) CONTINUED - 10 Question/Answer Sheet COMPSCI 101 I D: ..................................................................... Question 3 (6 marks) Complete the output produced when the following start() method is executed. public void start() { int n = 1; String s = "Hello World"; String[] car = new String[3]; car[2] = "Morgan"; method1(n, s, car); System.out.println("n: " + n); System.out.println("s: " + s); System.out.println("car[2]: " + car[2]); } private void method1(int i, String word, String[] name) { i = 3; word = "Goodbye"; name[2] = "Corvette"; } n: s: car[2]: (6 marks) CONTINUED - 11 Question/Answer Sheet COMPSCI 101 I D: ..................................................................... Question 4 (7 marks) a) Given the array definition below: String[] monthNames = { "January", "February", "March", "April", "May", "June", "July", "August", "September","October", "November", "December" }; what is printed by the following statement? System.out.println(monthNames[6]); (2 marks) b) Complete the printShortestMonth() method, which looks at each element in the String array, months, and prints the element with the fewest letters in its name. private void printShortestMonth(String[] months) { } (5 marks) CONTINUED - 12 Question/Answer Sheet COMPSCI 101 I D: ..................................................................... Question 5 (7 marks): As accurately as possible, show what would be drawn in the window by the following program. Grid lines have been drawn on the window to help you. The gap between adjacent gridlines is 10 pixels. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MyJPanel extends JPanel { public void paintComponent(Graphics g){ super.paintComponent(g); drawThing(g, 20, 40, 20); } public void drawThing(Graphics g, int x, int y, int size) { g.drawOval(x, y, size * 2, size * 2); g.drawLine(x, y + size * 3, x + size * 2, y + size * 2); g.fillRect(x + size / 2, y + size * 3, size, size); g.drawString("101", x + size * 3 / 2, y + size * 4); } } CONTINUED - 13 Question/Answer Sheet COMPSCI 101 I D: ..................................................................... (7 marks) CONTINUED - 14 Question/Answer Sheet COMPSCI 101 I D: ..................................................................... Question 6 (7 marks): Complete the getAverageHeight() method which has one parameter, an array of Rectangle objects. The method returns the average height of the Rectangles in the parameter array. public void start() { Rectangle[] rects = { new Rectangle(20, 30, 50, 40), new Rectangle(50, 60, 10, 20), new Rectangle(10, 90, 20, 45) }; double average = getAverageHeight(rects); System.out.println("Average height: " + average); } When the above start() method is executed with the completed getAverageHeight() method the output is: Average height: 35.0 Notes: The Rectangle array passed as a parameter may have any number of elements. You may assume that there is at least one element in the parameter array and that none of the elements are null. CONTINUED - 15 Question/Answer Sheet private COMPSCI 101 I D: ..................................................................... getAverageHeight ( ){ } (7 marks) CONTINUED - 16 Question/Answer Sheet COMPSCI 101 I D: ..................................................................... Question (7 7 marks) The following JPanel responds to MouseEvents. Initially the JPanel displays a filled rectangle on the right hand side of the window, referred to as the base rectangle. When the user presses the mouse, a red horizontal bar is displayed from the base rectangle to the x position where the user pressed the mouse. If the user presses the mouse inside the base rectangle or to the right of the base rectangle, the horizontal bar should not appear in the JPanel. The following screen shots show the behaviour of the completed JPanel. The following 14 statements are part of the code. Place each number in the correct place in the AJPanel definition on the next page so that the JPanel executes as described above. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. MouseEvent e implements MouseListener repaint(); private int barLeft; addMouseListener(this); Graphics g public void mouseClicked(MouseEvent e) {} barLeft = e.getX(); extends JPanel import java.awt.event.*; if (barLeft >= BASE_LEFT) { barLeft = BASE_LEFT; } barLeft = BASE_LEFT; g. fillRect(barLeft, BAR_Y, barWidth, BAR_HEIGHT); int barWidth = BASE_LEFT - barLeft; CONTINUED - 17 Question/Answer Sheet COMPSCI 101 I D: ..................................................................... import java.awt.*; import javax.swing.*; public class AJPanel { private static final int BAR_Y = 60; private static final int BAR_HEIGHT = 20; private private private private static static static static final final final final int int int int BASE_TOP = BAR_Y - 40; BASE_LEFT = 350; BASE_HEIGHT = 100; BASE_WIDTH = 10; public AJPanel() { } public void mousePressed( ){ } public void paintComponent( ){ super.paintComponent(g); g.setColor(Color.BLACK); g.fillRect(BASE_LEFT, BASE_TOP, BASE_WIDTH, BASE_HEIGHT); g.setColor(Color.RED); } public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvente){} public void mouseExited(MouseEvent e){} } (7 marks) CONTINUED - 18 Question/Answer Sheet COMPSCI 101 I D: ..................................................................... Question 8 (7 marks): The JPanel defined on the next page contains one JTextField component and two JButton components: valueT a JTextField which contains an int value, increaseB a JButton displaying the String, INCREASE, decreaseB a JButton displaying the String, DECREASE. Below is a screenshot of the JPanel when it is first displayed. The valueT JTextField displays the number 0. When the user presses the "INCREASE" JButton, the value in the valueT JTextField increases by a random number between 1 and 5 (inclusive). When the user presses the "DECREASE" JButton, the value in the valueT JTextField decreases by a random number between 1 and 5 (inclusive). You are required to complete the JPanel definition on the next page so that the JPanel behaves as described above. You MUST use the variables given in the code. The screenshots below show an example of the JPanel when the user presses the "INCREASE" JButton twice and then presses the "DECREASE" JButton twice. CONTINUED - 19 Question/Answer Sheet COMPSCI 101 I D: ..................................................................... import javax.swing.*; import java.awt.*; public class AJPanel extends JPanel { private JTextField valueT; private JButton increaseB, decreaseB; public AJPanel() { valueT = new JTextField(5); increaseB = new JButton("INCREASE"); decreaseB = new JButton("DECREASE"); add(increaseB); add(valueT); add(decreaseB); } public void ( e) { CONTINUED - 20 Question/Answer Sheet COMPSCI 101 I D: ..................................................................... } } (7 marks) Question 9 (3 marks): The Time24Hour class has two int instance variables, hour and minutes. Complete the equals() method for the Time24Hour class. This method returns true if both objects represent the same time, false otherwise. public boolean equals(Time24Hour other) { } (3 marks) CONTINUED - 21 Question/Answer Sheet COMPSCI 101 I D: ..................................................................... Question 10 (6 marks): In the following Bank class: public class Bank { //put instance variables here public Bank(Person manager, Time24Hour openTime, int tellers) { //put the constructor code here } ... other code omitted ... } (6 marks) a) declare three instance variables: an instance variable, manager, of type Person, an instance variable, openingTime, of type Time24Hour, specifying the bank opening time, and an instance variable, maxTellers, of type int, specifying the maximum number of teller positions. b) complete the constructor which has the following 3 parameters: a Person parameter which specifies the person who is the manager, a Time24Hour object which specifies when the bank opens, and an int which specifies the maximum number of tellers. CONTINUED - 22 Question/Answer Sheet COMPSCI 101 I D: ..................................................................... Question 11 (7 marks) You are required to complete the following JPanel which uses a Timer object. The Timer object is created with a delay of 100 milliseconds. Initially nothing is displayed inside the JPanel except a thin rectangle down the right hand side of the window. The Timer starts when the user first presses the UP arrow key. When the Timer starts, a black line, which increases in length, appears from the left hand side of the JPanel. The length of the line increases by ten pixels with each tick of the Timer, i.e. the end of the line increases by ten pixels each time as the line grows to the right. When the end of the line reaches 200, the line starts shrinking, i.e. the end of the line decreases by ten pixels. When the length of the line is zero, the line starts growing again. By pressing the UP and DOWN arrow keys, the user controls when the line starts and stops growing/shrinking. When the user presses the UP arrow key, the Timer should start and the line continues growing/shrinking. When the user presses the DOWN arrow key, the Timer should stop. When the user presses the UP arrow key again, the Timer starts again and the line continues growing/shrinking, etc. Below are some screenshots of the JPanel in action. The first screenshot shows the JPanel when it is first displayed. The next five screenshots show the JPanel after the user has pressed the UP arrow key and the line has started growing. The next three screenshots show the line shrinking after the end of the line has reached 200 pixels. The last two screenshots show the line growing again after the end of the line has shrunk to 0 pixels. Notes: The start of the line is ALWAYS given by the constants: public static final int LINE_LEFT = 0; public static final int LINE_DOWN = 50; You MUST use the variables and constants given in the code. When the user first presses the UP arrow key the line starts increasing its length. CONTINUED - 23 Question/Answer Sheet COMPSCI 101 I D: ..................................................................... import javax.swing.*; import java.awt.*; import java.awt.event.*; public class AJPanel extends JPanel { //The start of the line public static final int LINE_LEFT = 0; public static final int LINE_DOWN = 50; private int lineEnd; private boolean isIncreasing; private Timer t; public AJPanel() { isIncreasing = true; lineEnd = LINE_LEFT; } public void actionPerformed(ActionEvent e) { } CONTINUED - 24 Question/Answer Sheet COMPSCI 101 I D: ..................................................................... public void keyPressed(KeyEvent e) { } public void paintComponent(Graphics g) { super.paintComponent(g); //the thin rectangle displayed on the right //hand side of the window g.fillRect(200, 0, 4, 150); } public void keyReleased(KeyEvent e) {} public void keyTyped(KeyEvent e) {} } (7 marks) CONTINUED - 25 Question/Answer Sheet COMPSCI 101 I D: ..................................................................... OVERFLOW PAGE (If you have used this page, please indicate clearly under the relevant question that you have overflowed to this page) CONTINUED - 26 Question/Answer Sheet COMPSCI 101 I D: ..................................................................... OVERFLOW PAGE (If you have used this page, please indicate clearly under the relevant question that you have overflowed to this page) CONTINUED - 27 Question/Answer Sheet COMPSCI 101 I D: ..................................................................... ROUGH WORKING (WILL NOT BE MARKED) (You may use this page for rough working) CONTINUED - 28 Question/Answer Sheet COMPSCI 101 I D: ..................................................................... ROUGH WORKING (WILL NOT BE MARKED) (You may use this page for rough working)
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSECOND SEMESTER, 2008Campus: CityCOMPUTER SCIENCETESTPrinciples of Programming(Time allowed: 75 MINUTES)NOTE:Attempt ALL questionsWrite your answers in the space providedThere is space at the back for answer
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSECOND SEMESTER, 2008Campus: CityCOMPUTER SCIENCETESTPrinciples of Programming(Time allowed: 75 MINUTES)NOTE:Attempt ALL questionsWrite your answers in the space providedThere is space at the back for answer
University of Auckland - COMPSCI - 101
COMPSCI 101THE UNIVERSITY OF AUCKLANDSUMMER SEMESTER, 2008Campus: CityCOMPUTER SCIENCEPrinciples of Programming(Time allowed: TWO hours)NOTE:Attempt ALL questionsWrite your answers in the space providedThere is space at the back for answers that
University of Auckland - COMPSCI - 101
COMPSCI 101THE UNIVERSITY OF AUCKLANDSUMMER SEMESTER, 2008Campus: CityCOMPUTER SCIENCEPrinciples of Programming(Time allowed: TWO hours)NOTE:Attempt ALL questionsWrite your answers in the space providedThere is space at the back for answers that
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSUMMER SEMESTER, 2008Campus: CityCOMPUTER SCIENCETESTPrinciples of Programming(Time allowed: 75 MINUTES)NOTE:Attempt ALL questionsWrite your answers in the space providedThere is space at the back for answer
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSUMMER SEMESTER, 2008Campus: CityCOMPUTER SCIENCETESTPrinciples of Programming(Time allowed: 75 MINUTES)NOTE:Attempt ALL questionsWrite your answers in the space providedThere is space at the back for answer
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDFIRST SEMESTER, 2009Campus: CityCOMPUTER SCIENCEPrinciples of Programming(Time Allowed: TWO hours)NOTE: Attempt ALL questionsWrite your answers in the space providedThere is space at the back for answers that
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDFIRST SEMESTER, 2009Campus: CityCOMPUTER SCIENCEPrinciples of Programming(Time Allowed: TWO hours)NOTE: Attempt ALL questionsWrite your answers in the space providedThere is space at the back for answers that
University of Auckland - COMPSCI - 101
COMPSCI 101THE UNIVERSITY OF AUCKLANDFIRST SEMESTER, 2009Campus: CityTESTCOMPUTER SCIENCEPrinciples of Programming(Time allowed: 75 minutes)NOTE:Attempt ALL questionsWrite your answers in the space providedThere is space at the back for answers
University of Auckland - COMPSCI - 101
COMPSCI 101THE UNIVERSITY OF AUCKLANDFIRST SEMESTER, 2009Campus: CityTESTCOMPUTER SCIENCEPrinciples of Programming(Time allowed: 75 minutes)NOTE:Attempt ALL questionsWrite your answers in the space providedThere is space at the back for answers
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSECOND SEMESTER, 2009Campus: CityCOMPUTER SCIENCEPrinciples of Programming(Time Allowed: TWO hours)NOTE:You must answer all questions in this exam.No calculators are permittedAnswer in the space provided in t
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSECOND SEMESTER, 2009Campus: CityCOMPUTER SCIENCEPrinciples of Programming(Time Allowed: TWO hours)NOTE:You must answer all questions in this exam.No calculators are permittedAnswer in the space provided in t
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSEMESTER TWO, 2009Campus: CityCompSci 101TESTCOMPUTER SCIENCEPrinciples of Programming(Time allowed: 75 minutes)NOTE:Attempt ALL questionsWrite your answers in the space providedThere is space at the back f
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSEMESTER TWO, 2009Campus: CityCompSci 101TESTCOMPUTER SCIENCEPrinciples of Programming(Time allowed: 75 minutes)NOTE:Attempt ALL questionsWrite your answers in the space providedThere is space at the back f
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSUMMER SEMESTER, 2009Campus: CityCOMPUTER SCIENCEPrinciples of Programming(Time Allowed: TWO hours)NOTE: Attempt ALL questionsWrite your answers in the space providedThere is space at the back for answers that
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSUMMER SEMESTER, 2009Campus: CityCOMPUTER SCIENCEPrinciples of Programming(Time Allowed: TWO hours)NOTE: Attempt ALL questionsWrite your answers in the space providedThere is space at the back for answers that
University of Auckland - COMPSCI - 101
CompSci 101Question/Answer Sheet- Page 2 -CompSci 101 SS CSURNAME: . FORENAMES: .THE UNIVERSITY OF AUCKLANDQuestion 1 (40 marks)a) What output is produced by the following code?String sentence = &quot;I LOVE SUMMER SCHOOL!&quot;;String part = sentence.subs
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSUMMER SEMESTER, 2009Campus: CityCOMPUTER SCIENCETESTPrinciples of Programming(Time allowed: 75 MINUTES)NOTE: Attempt ALL questionsWrite your answers in the space providedThere is space at the back for answer
University of Auckland - COMPSCI - 101
VERSION 00000001COMPSCI 101THE UNIVERSITY OF AUCKLANDFIRST SEMESTER, 2010Campus: CityComputer SciencePrinciples of Programming(Time Allowed: TWO HOURS)SECTION A Question BookletNote: The use of calculators is NOT permitted. You should separate
University of Auckland - COMPSCI - 101
VERSION 00000001COMPSCI 101THE UNIVERSITY OF AUCKLANDFIRST SEMESTER, 2010Campus: CityComputer SciencePrinciples of Programming(Time Allowed: TWO HOURS)SECTION A Question BookletNote: The use of calculators is NOT permitted. You should separate
University of Auckland - COMPSCI - 101
VERSION 00000003COMPSCI 101THE UNIVERSITY OF AUCKLANDFIRST SEMESTER, 2010Campus: CityCOMPUTER SCIENCETESTPrinciples of Programming(Time Allowed: 75 minutes)Note: The use of calculators is NOT permitted. Compare the test version number on the Te
University of Auckland - COMPSCI - 101
VERSION 00000003COMPSCI 101THE UNIVERSITY OF AUCKLANDFIRST SEMESTER, 2010Campus: CityCOMPUTER SCIENCETESTPrinciples of Programming(Time Allowed: 75 minutes)Note: The use of calculators is NOT permitted. Compare the test version number on the Te
University of Auckland - COMPSCI - 101
THE UNIVERSITY OF AUCKLANDSECOND SEMESTER, 2010Campus: CityCOMPUTER SCIENCEPrinciples of Programming(Time Allowed: TWO hours)NOTE:You must answer all questions in this exam.No calculators are permittedAnswer in the space provided in this booklet.
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSECOND SEMESTER, 2010Campus: CityCOMPUTER SCIENCEPrinciples of Programming(Time Allowed: TWO hours)NOTE:You must answer all questions in this exam.No calculators are permittedAnswer in the space provided in t
University of Auckland - COMPSCI - 101
THE UNIVERSITY OF AUCKLANDSECOND SEMESTER, 2010Campus: CityCOMPUTER SCIENCETEST SOLUTIONSPrinciples of Programming(Time Allowed: 75 minutes)NOTE:You must answer all questions in this test.No calculators are permittedAnswer in the space provided
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSECOND SEMESTER, 2010Campus: CityCOMPUTER SCIENCETESTPrinciples of Programming(Time Allowed: 75 minutes)NOTE:You must answer all questions in this test.No calculators are permittedAnswer in the space provide
University of Auckland - COMPSCI - 101
Question/Answer SheetCompSci101THE UNIVERSITY OF AUCKLANDSUMMER SEMESTER, 2010Campus: CityCOMPUTER SCIENCEPrinciples of Programming(Time Allowed: TWO hours)NOTE:You must answer all questions in this exam.No calculators are permittedAnswer in th
University of Auckland - COMPSCI - 101
Question/Answer SheetCompSci101THE UNIVERSITY OF AUCKLANDSUMMER SEMESTER, 2010Campus: CityCOMPUTER SCIENCEPrinciples of Programming(Time Allowed: TWO hours)NOTE:You must answer all questions in this exam.No calculators are permittedAnswer in th
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSUMMER SEMESTER, 2010Campus: CityCOMPUTER SCIENCETESTPrinciples of Programming(Time Allowed: 75 minutes)NOTE:You must answer all questions in this test.No calculators are permittedAnswer in the space provide
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSUMMER SEMESTER, 2010Campus: CityCOMPUTER SCIENCETESTPrinciples of Programming(Time Allowed: 75 minutes)NOTE:You must answer all questions in this test.No calculators are permittedAnswer in the space provide
University of Auckland - COMPSCI - 101
VERSION 00000001COMPSCI 101THE UNIVERSITY OF AUCKLANDFIRST SEMESTER, 2011Campus: CityCOMPUTER SCIENCEPrinciples of Programming(Time Allowed: TWO hours)Note: The use of calculators is NOT permitted. You should separate the Section A Question Book
University of Auckland - COMPSCI - 101
VERSION 00000001COMPSCI 101THE UNIVERSITY OF AUCKLANDFIRST SEMESTER, 2011Campus: CityCOMPUTER SCIENCEPrinciples of Programming(Time Allowed: TWO hours)Note: The use of calculators is NOT permitted. You should separate the Section A Question Book
University of Auckland - COMPSCI - 101
VERSION 00000003COMPSCI 101THE UNIVERSITY OF AUCKLANDFIRST SEMESTER, 2011Campus: CityCOMPUTER SCIENCETESTPrinciples of Programming(Time Allowed: 75 minutes)Note: The use of calculators is NOT permitted. For Section A, use a dark pencil to mark
University of Auckland - COMPSCI - 101
VERSION 00000003COMPSCI 101THE UNIVERSITY OF AUCKLANDFIRST SEMESTER, 2011Campus: CityCOMPUTER SCIENCETESTPrinciples of Programming(Time Allowed: 75 minutes)Note: The use of calculators is NOT permitted. For Section A, use a dark pencil to mark
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSECOND SEMESTER, 2011Campus: CityCOMPUTER SCIENCEPrinciples of Programming(Time Allowed: TWO hours)NOTE:You must answer all questions in this test.No calculators are permittedAnswer in the spaces provided in
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSECOND SEMESTER, 2011Campus: CityCOMPUTER SCIENCEPrinciples of Programming(Time Allowed: TWO hours)NOTE:You must answer all questions in this test.No calculators are permittedAnswer in the spaces provided in
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSECOND SEMESTER, 2011Campus: CityCOMPUTER SCIENCETESTPrinciples of Programming(Time Allowed: 75 minutes)NOTE:You must answer all questions in this test.No calculators are permittedAnswer in the spaces provid
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSECOND SEMESTER, 2011Campus: CityCOMPUTER SCIENCETESTPrinciples of Programming(Time Allowed: 75 minutes)NOTE:You must answer all questions in this test.No calculators are permittedAnswer in the spaces provid
University of Auckland - COMPSCI - 101
THE UNIVERSITY OF AUCKLANDSUMMER SEMESTER, 2011Campus: CityCOMPUTER SCIENCEPrinciples of Programming(Time Allowed: TWO hours)NOTE:You must answer all questions in this exam.No calculators are permittedAnswer in the space provided in this booklet.
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSUMMER SEMESTER, 2011Campus: CityCOMPUTER SCIENCEPrinciples of Programming(Time Allowed: TWO hours)NOTE:You must answer all questions in this exam.No calculators are permittedAnswer in the space provided in t
University of Auckland - COMPSCI - 101
THE UNIVERSITY OF AUCKLANDSUMMER SEMESTER, 2011Campus: CityCOMPUTER SCIENCETESTPrinciples of Programming(Time Allowed: 75 minutes)NOTE:You must answer all questions in this test.No calculators are permittedAnswer in the space provided in this bo
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSUMMER SEMESTER, 2011Campus: CityCOMPUTER SCIENCETESTPrinciples of Programming(Time Allowed: 75 minutes)NOTE:You must answer all questions in this test.No calculators are permittedAnswer in the space provide
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSUMMER SEMESTER, 2012Campus: CityCOMPUTER SCIENCETESTPrinciples of Programming(Time Allowed: 75 minutes)NOTE:You must answer all questions in this test.No calculators are permittedAnswer in the space provide
University of Auckland - COMPSCI - 101
CompSci 101THE UNIVERSITY OF AUCKLANDSUMMER SEMESTER, 2012Campus: CityCOMPUTER SCIENCETESTPrinciples of Programming(Time Allowed: 75 minutes)NOTE:You must answer all questions in this test.No calculators are permittedAnswer in the space provide
University of Auckland - COMPSCI - 101
COMPSCI 101SUMMER SCHOOL2012- Principles of Programming Lecture times and locations (rooms subject to change)Monday: 10:00 am - 11:00 am ClockT029/105-029 (ClockTower building)Tuesday: 10:00 am - 11:00 am ALR5/421W-301 (Architecture building)Wednesd
University of Auckland - COMPSCI - 101
2!Welcome to CompSci 1 1!Will be available on the web!Introduction to the Compsci 101 course!!Algorithms!!Programming steps!!!Lab One Worksheet!Course Information Document3!CompSci 101 People!People cont.!Ann Cameron (Lab Supervisor) !!4
University of Auckland - COMPSCI - 101
Computer Science 1 1 SS CLecture 2 Contents!2!Computer Organisation!Most computers consist of three major components:Compilers, interpreters and java!javac, java commands!Installing Java!Writing the &quot;Hello World&quot; program!!Coursebook: 1! a proce
University of Auckland - COMPSCI - 101
Computer Science 1 1 SS CLecture 3 Contents!2!Review!Write the source code for the application (whichstarts the program).Java Syntax!Displaying Output!MyApplication.javapublic class MyApplication cfw_public static void main(String[] args) cfw_M
University of Auckland - COMPSCI - 101
Computer Science 1 1 SS CLecture 4 Contents!2!Review!What is the output of the following two programs?Java has eight primitive types!Storing information - variables!The assignment statement!Expressions !Modulus!Increment, decrement operators!!
University of Auckland - COMPSCI - 101
Computer Science 1 1 SS C Lecture 5 Contents&quot;&gt; java ReviewAppDeposit $455Current balance $955.535Review&quot;1 public class Review cfw_public void start() cfw_2int amount, leftOvers;3 double balance; 4amount = 435;5 6 l
University of Auckland - COMPSCI - 101
Computer Science 1 1 SS C Lecture 6 Contents&quot;Java - supports object orientedprogramming!2!The world is made up of real world objects e.g.students, dogs, cars, cats, books. !Objects!String objects!String instance methods!!Coursebook: 6!!Object
University of Auckland - COMPSCI - 101
Computer Science 1 1 SS C Lecture 7 Contents&quot;13 blocksLook at the following program which, given the number ofhours and minutes, evaluates the number of complete tenminute blocks.Dening methods: !parameters, !return values, !return statement !!
University of Auckland - COMPSCI - 101
Computer Science 1 1 SS C Lecture 9 Contents&quot;e0Review&quot;Methods!Scope of variables!Reasons for using methods&quot;!!Coursebook: 9!!Methods and parameters what is the output?!1public class MyProgram cfw_public void start() cfw_int x
University of Auckland - COMPSCI - 101
Computer Science 1 1 SS C Lecture 10 Contents&quot;1 String a, b;a2 = new String(&quot;mbc&quot;);b3 = a;4 = b.substring(0, 1);a5 System.out.println(a + b);More String instance methods !2!mmbcReview&quot;!boolean variab
University of Auckland - COMPSCI - 101
Computer Science 1 1 SS C Lecture 11 Contents&quot;2!Nested if statements!nested if statements!!Any javastatement,including anotherif statement, canoccur inside thethen or else partsof if statements.!Indentation of if statements.!!if . else if .
University of Auckland - COMPSCI - 101
Computer Science 1 1 SS C Lecture 12 Contents&quot;2!Control Structures&quot;It is important to understand how the computer works!its way through a program, nding which instructionto execute next.!Loops: initialisation, condition, body, increment!!while l
University of Auckland - COMPSCI - 101
Computer Science 1 1 SS C Lecture 13 Contents&quot;2!Why do we need arrays?&quot;Let's say I want to store!the bank balance amountfor every student in thisclass.!Why do we need arrays?!!Declaring an array.!!Creating the array space.!!Assigning to ind
University of Auckland - COMPSCI - 101
Computer Science 1 1 SS CLecture 14 Contents!2!Java is Object Oriented!Java is an object oriented programming language!Representing real world objects in programs!Structure of a class denition!Instance variables!Constructors!Instance methods!!C
University of Auckland - COMPSCI - 101
Computer Science 1 1 SS CLecture 15 Contents!2!Time24Hr - instance variables!Consider dening a class to represent hours and minutes ona 24 hour clock.!! public class Time24Hr cfw_1!private int hour; 2!private int minutes;3 !4
University of Auckland - COMPSCI - 101
Computer Science 1 1 SS CLecture 16 Contents!2!ForSale - instance variables!Consider dening a class to represent items whichare for sale on a website. !Practice dening a class - ForSale class!this!null,!equals() method!Equality of objects!Below
University of Auckland - COMPSCI - 101
CompSci 101 Lecture 18 - Revision 273. Write the charsMatchExactly() method so that it correctly calculates the number of characterswhich are exactly the same, and in exactly the same position in the two Strings which can be of anylength. You can assum