Java 01

Topics: Randomness, Return statement, Face Pages: 11 (914 words) Published: February 23, 2013
TMA 01

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);
this.getBottomMiddleSpot().setYPos(48);
this.getBottomLeftSpot().setXPos(3);
this.getBottomLeftSpot().setYPos(48);
this.getBackground().setXPos(0);

}

ii)

/**
* 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().setYPos(48);
this.getBottomLeftSpot().setXPos(3);
this.getBottomLeftSpot().setYPos(48);

this.face1();

}

B)

/**
* Constructor for objects of class Dice
*/
public Dice()
{
super();
this.background = new Square();
this.background.setLength(75);
this.topLeftSpot = new Circle();
this.topMiddleSpot = new Circle();
this.topRightSpot = new Circle();
this.middleSpot = new Circle();
this.bottomLeftSpot = new Circle();
this.bottomMiddleSpot = new Circle();
this.bottomRightSpot = new Circle();
this.reset();
}

iii)

/**
* Sets the face of the receiver to 1 spot
*/
public void face1()
{
this.getTopLeftSpot().setColour(OUColour.ORANGE);
this.getTopMiddleSpot().setColour(OUColour.ORANGE);
this.getTopRightSpot().setColour(OUColour.ORANGE);
this.getMiddleSpot().setColour(OUColour.BLUE);
this.getBottomLeftSpot().setColour(OUColour.ORANGE);
this.getBottomMiddleSpot().setColour(OUColour.ORANGE); this.getBottomRightSpot().setColour(OUColour.ORANGE);
}
/**...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Java Essay
  • Java Javascript Essay
  • Comparison of Java, Javascript, Java Applets and Java Beans Essay
  • Java Project Essay
  • Java vs. C++ Essay
  • Java Ring Essay
  • Essay on Java Cis Assignment 1
  • Java Applets Essay

Become a StudyMode Member

Sign Up - It's Free