Questionanswer sheet page 13 compsci 101 ac surname

This preview shows page 13 - 19 out of 24 pages.

Question/Answer Sheet - Page 13 - CompSci 101 AC SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED Question 7 (5 marks) What is the output of the following application: public class Q7 { public static void main(String[] args){ int value = 0; for(int i=4; i>0; i=i-2) { System.out.println("AA"); for(int j=0; j<i; j=j+3) { if(i>2) System.out.println("i: " + i + ", j: " + j + ", value: " + value); value++; } } System.out.println("value: "+value); }
Image of page 13

Subscribe to view the full document.

Question/Answer Sheet - Page 14 - CompSci 101 AC SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED Question 8 (10 marks) Complete the applet below so that it displays the following pattern. The number of rows is given by the constant, LINES . The size of each circle/square is given by the constant, SIZE . The top left position of the pattern is 20, 20. NOTE: Some constants and some variables are declared and initialized for you. You may choose not to use the variables. Your code MUST use the two constants LINES and SIZE . You MUST use a nested loop to draw the pattern. import java.applet.*; import java.awt.*; public class Q8 extends Applet { public void paint(Graphics g) { final int LINES = 7; final int SIZE = 20; int toDoAcross = LINES; int startX = 20; int y = 20; int x;
Image of page 14
Question/Answer Sheet - Page 15 - CompSci 101 AC SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED } }
Image of page 15

Subscribe to view the full document.

Question/Answer Sheet - Page 16 - CompSci 101 AC SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED Question 9 (5 marks) There are two syntax errors in the following program which prevent it from compiling. You need to locate the two errors, circle them clearly, and provide the simplest correction for them. public class Q9 { /* This program prints a greeting /* public static void main(String[] args) { System.out.println("Hello world!"); if (Math.random < 0.5) System.out.println("Goodbye"); } }
Image of page 16
Question/Answer Sheet - Page 17 - CompSci 101 AC SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED Question 10 (8 marks) Examine the following source code for the class WordNum : public class WordNum { private static int number=0; private String word; private int value; public WordNum(String s) { word = s; value = s.length(); number = number + value; } public void addToWd(String toAdd) { word = word + " " + toAdd; number = number + toAdd.length() + 1; value = word.length(); } public String toString() { String temp = number + ": "; temp += "word: " + word + " value: " + value; return temp; } } This class is used in the application Q10 . The source code for this application is given below: public class Q10 { public static void main(String[] args){ WordNum w1, w2; w1 = new WordNum("GO"); w2 = new WordNum("STOP"); w1.addToWd("SOFTLY"); System.out.println(w1.toString()); System.out.println(w2.toString()); } } What is the output when the application Q10 is executed?
Image of page 17

Subscribe to view the full document.

Question/Answer Sheet - Page 18 - CompSci 101 AC SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED Question 11 (12 marks) The following application, Q11 , uses a class called DemoCall . The class, DemoCall , keeps the details of a call to a demonstrator in the lab. A DemoCall object stores the time at which the call is made (hours, using 24 hour time, and minutes), the login name of the student, and the position at which they are in the demonstrator queue. The instance variables in the DemoCall class have been declared for you.
Image of page 18
Image of page 19
You've reached the end of this preview.
  • Summer '12
  • AdrianaFerraro
  • Computer Science, Following, ........., Rectangle, Given name

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern