Question 1
i)
A)
Reciever = Kermitt
Message = sameColourAs(gribbit)
Message send = kermit.sameColourAs(gribbit)
Argument = gribbitt
B)
kermit.right(); kermit.getPosition(); gribbit.brown(); gribbit.getColour(); C)
1, None
2, Right
3, None
4, None
5, Brown
6, None
ii)
A)
Two frog objects exist after the code has been executed. The two variables that the objects refer to are croaker and hoppy. The varialble of croaker is created in statement 2 and the variable of Kermit is changed to hoppy in statement 5.
B)
Kermit = Purple
Statement 3 initially changes the colour of Kermit to blue but when the variable is renamed in statement 5 it changes the colour to purple.
Croaker = Yellow
Statement 4 sets the colour of the object to yellow.
Hoppy = Purple
Statement 6 sets the object colour to purple.
C)
Constructor = new frog
Variable = Kermit
Type = Frog
Operator = equals sign
ii)
Statement 1 would cause and error as it contains the wrong type as it is looking for hoverfrog but can only find frog. Statement 2 is ok as the variable has been renamed as Hoverfrog.
Question 2
i)
/** * Sets the relevant spots in there correct locations. */ public void reset() {
this.getTopLeftSpot().setXPos(3); this.getTopLeftSpot().setYPos(3); this.getTopMiddleSpot().setXPos(25); this.getTopMiddleSpot().setYPos(3); this.getTopRightSpot().setXPos(48); this.getTopRightSpot().setYPos(3); this.getMiddleSpot().setXPos(25); this.getMiddleSpot().setYPos(25); this.getBottomMiddleSpot().setXPos(25); this.getBottomMiddleSpot().setYPos(48); this.getBottomRightSpot().setXPos (48); this.getBottomRightSpot().setYPos (48); this.getBottomMiddleSpot().setXPos(25);