question archive Part A: General Knowledge (THERE WILL BE 10 QUESTIONS HERE WORTH 2 MARKS EACH - The questions will be based on material taken from the study guide and the textbook
Subject:Computer SciencePrice: Bought3
Part A: General Knowledge (THERE WILL BE 10 QUESTIONS HERE WORTH 2 MARKS EACH - The questions will be based on material taken from the study guide and the textbook. The total here is 20 marks)
1) Who was the first programmer? (2 marks)
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
2) Explain two reasons how and why we use comments in code? (2 marks)
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
3) What is a static method in Java? Use and example from the API documentation to support your answer. (2 marks)
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
4) What is the purpose of pseudocode? Provide an example of pseudocode. (2 marks)
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
5) What is meant by initialising a variable? Use an example to explain you answer. (2 marks)
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
6) How many parameters can the setPaintOrder method take? Provide an example of the setPaintOrder method. (2 marks)
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
7) What is a good technique that is commonly used to debug looping through arrays? (2 marks)
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
8) Name one thing that can go wrong with a while loop. (2 marks)
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
9) What does the method, getOneIntersectingObject return? (2 mark)
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
10) In Java programming, we can overload methods. Explain what method overloading is, using an example to support your answer. (2 mark)
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
__________________________________________________________________________________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Part B: Java programming logic (THERE WILL BE 20 QUESTIONS HERE- These questions will test your knowledge of programming and programming logic. The questions may be taken from the study guide and the quizzes. There are 40 marks total here!)
1) In the spaces, write the values in the variables after the code has been executed: (3 marks)
int a = 2;
int b = 3;
int c = 4;
a = c;
c = a;
b = a;
The value in a is ____________
The value in b is ____________
The value in c is ____________
2) This code is part of a program where the player walks around eating apples. For each letter below (a, b and c), explain what that line of code is doing. (3 marks)
aa
c
b
public void lookForApple()
{
if ( canSee(Apple.class) )
{
eat(Apple.class);
Greenfoot.playSound("slurp.wav");
applesEaten += 1;
}
// more code
}
a. __________________________________________________________________________________________________________________________________________________________________________________________________________________
b. __________________________________________________________________________________________________________________________________________________________________________________________________________________
c. __________________________________________________________________________________________________________________________________________________________________________________________________________________
3) For the Java method signature below, answer the following questions:
a. What is the method name?
b. Does the method return a value? If yes, what is the type of the return value?
c. How many parameters does the method have?
d. Write a sample Java method call for the method signature; that is: how would you call the method in your code?
public boolean someMethod () (2 marks)
a. ___________________________________
b. ___________________________________
c. ___________________________________
d. ___________________________________
public void setAge (int age) (2 marks)
a. ___________________________________
b. ___________________________________
c. ___________________________________
d. ___________________________________
4) Name one of the static methods in the Greenfoot class that returns an int. (2 marks) Hint - you may look at the API documentation.
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
5) This question refers to the following Java code, where the variables p, q, r and s all have integer values. The values in these variables at the start of this code are
p = 1, q = 2, r = 3, s = 4;
What would be the value in variable s after the following code is executed? (2 marks)
if (p < q)
{
if (q < 4)
{
s = r;
} else {
s = s;
}
}
s = ____________
6) Identify two errors in the following code (2 marks).
int i = 0;
while (i > 100)
{
Greenfoot.playSound(beep.wav);
i +=1;
}
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
7) In your practical skills assessment, which method did you use to check when a Food or Enemy object encountered the edge of the world? Use an example to support your answer. (2 marks).
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
8) Write an example of a method comment for the method below. You only need to explain the method signature. Use correct commenting symbols in your answer. (2 marks)
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
9) Which of the following explains the definition of a constructor? (1 mark)
(a) a constructor is a method that has the same name as the class;
(b) a constructor is a method that has no return type;
(c) a constructor is a method that can have zero or many parameters;
(d) a constructor is a method that is called automatically when an object is created from the class;
(e) all of the above.
10) In Java, there are object methods and class methods. What is another name for class methods? Use and example to support your answer. (2 marks)
____________________________________________________________________________________________________________________________________________________
__________________________________________________________________________
11) Given this code in the World constructor, what will happen in the world when the program starts? (2 marks).
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
12) What type of variable stores the value "Augusta Ada"? Use an example declaration and initialisation to demonstrate your answer. (2 marks).
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
13) Given the following code:
double[] fractions = {0.1, 0.2, 0.25, 0.5, 0.75};
What is the value stored at fractions[2]? (2 marks)
_________________________________________________________________________
14) _____________________ is where a subclass can use methods of its parent class (1 mark)
15) Write code on one line to create a public variable called numberSquare with initial value 16. Don't forget the semi-colon at the end. (2 marks)
_________________________________________________________________________
16) Given the following code:
if (Greenfoot.isKeyDown("up"))
{
// move the object up
}
Write the type of the parameter of the method isKeyDown. ___________________. (1 mark)
17) Consider the following code:
int x = 0;
int i = 0;
while (i < 3)
{
x = x + i;
i = i + 1;
}
What is the value of x at the end of the last time through the loop? _______. (1 mark)
18) In the method signature below:
boolean isTouching(Class cls)
a. The parameter type is:_________________________________________. (1 mark)
b. The parameter name is:________________________________________. (1 mark)
19) In Java, what is the difference between a primitive type and an object type? Use examples to support your answer. (2 marks)
____________________________________________________________________________________________________________________________________________________
__________________________________________________________________________
20) In Greenfoot, explain how you may use code to get a random number between 0 and 10. Use code to support your answer. (2 marks)
____________________________________________________________________________________________________________________________________________________
__________________________________________________________________________
Part C: Java Programming (YOU WILL BE GIVEN SCENARIOS AND ASKED TO WRITE CODE FOR ONE OR MORE OF THE CLASSES. This section is designed to test your knowledge of programming code and programming structures. These questions will come from the portfolio activities and the practical skills game. There are 40 marks in this section!)
(This is an example of the text you will see in your exam) In this section, you are going to create an AppleWorld that contains 10 apples, each one with its own yumminess and size ratings. Use this scenario as you think about the following questions.
SCENARIO: Orchard World
You will be asked to create code for three of the classes, The OrchardWorld, Man and Apple classes.
You will be asked to write code for some of the classes. Below is a small example of what you can expect in the exam.
The following questions relate to how you may create the Apple World scenario.
2) When you create a new scenario, the scenario is created with a World class called MyWorld and no Actor classes. Explain how you may add the classes in the above image to the scenario and assign images to each of these classes. (4 marks)
The following programming is for the Apple World Class.
1) Assume a new world called AppleWorld has been created for the game.
a. In our world constructor we need to set the size of the world. Write a single line of code to create the world with a size of 800x 600 with a pixel size of 1. (1 mark)
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
b. Our Apple class has two constructors (yet to be coded). We will use a default constructor, one without parameters for this question. Using a while loop, write code that uses the default constructor to add seven (7) Apple objects to the scene at random locations in the world.
(3 marks)
__________________________________________________________________________________________________________________________________________
_______________________________________________________________________________________________________________________________________________________________________________________________________________
_____________________________________________________________________
_______________________________________________________________________________________________________________________________________________________________________________________________________________
The following programming is for the Man Class.
1) When the Man moves, the program switches between two images to make the Man object appear to be walking. Write a Java method called switchImage that will switch between image1 and image2 when it is called. The names of the files for the man images are "man1.png" and "man2.png" (3 marks)
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
The following programming is for the Food Class.
1) The Food class will require one (1) value that are its type. The type will be used to determine which image will be used. Declare an instance variable called type. Do not initialise the variable. The values held in type will be "Green Apple", "Red Apple". (1 mark)
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
This is a reminder that you will be asked to write code for more than one class and potentially more than one scenario. The following is what you could expect to write in the exam
1) You may have to program a Player or an Enemy class. You might be asked to;
a. declare and initialise variables
b. make a player or enemy objects move
c. add object interaction to these classes
d. write constructors that may or may not have parameters
e. program a constructor to assign different properties to objects
f. write a method that returns a value
2) You may have to program a World class. You might be asked to;
a. write code to create a world to a certain size
b. write code to add objects to the scene using different Player or Enemy constructors
c. write a loop (this could include while loops, for loops and for-each loops)
d. declare and initialise an array
e. use an array to pass values to a constructor
f. display a score
3) You may have to program a Food class. You might be asked to;
a. declare and initialise variables
b. declare and initialise Image variables
c. write constructors that may or may not have parameters
d. program a constructor to assign different properties to objects
e. write a method that returns a value
f. write code to make the food objects perform actions