Monday, 30 August 2010

Ap CS First Test

Computer Science Test
  First we need to create a new class called “Box”. We need to clear the methods inside the Box and copy all the coding from “Square” to Box. This is because we get our parent coding or parent methods from square. We know that the parameters of the Box are doing to be in a different ration, because the hands and legs are not in a square shape. Now we need to change the parameters. We need to change the method “int size” to “int width” and “int height”. This is because the proportion of a square is always equal i.e 1:1, while in a box, which is a rectangle, it has changing proportions that is why it has a width and height method. Now we compile the Box. We now work with the Picture coding. We have to start with changing the new class by making new parameters or making body methods, like box body, box leg left, box hand left, box hand right, and box leg right. My coding looks like this:
public void draw()
 {
 Box body = new Box();
  body.changeColor("black");
  body.moveVertical(100);
  body.moveHorizontal(25);
  body.makeVisible();
 
    Circle head = new Circle();
  head.changeColor("green");
  head.moveHorizontal(60);
  head.moveVertical(60);
  head.makeVisible();
 
    Triangle hat = new Triangle();
  hat.changeColor("blue");
  hat.moveVertical(80);
  hat.moveHorizontal(45);
  hat.makeVisible();
 
  Box right = new Box();
  right.changeColor("black");
  right.moveVertical(20);
  right.moveHorizontal(-40);
  right.changeWidth(40);
  right.changeHeight(20);
  right.makeVisible();
 
  Box left = new Box();
  left.changeColor("blue");
 left.moveVertical(80);
  left.moveHorizontal(65);
  left.changeWidth(40);
 left.changeHeight(20);
  left.makeVisible();
 }
Then I had to work with parameters in order to align the objects, like the hands and the body, and the legs and the head together. It was hard because you have to visualize the placement of the objects and you have to estimate the values and try to make them place together.  After you are done aligning the objects, you have to compile the “picture” coding. You have to change the colours of the objects to make it similar or resemble the peasant. Then you call the method “new Picture()”. Then you call the method, “void draw()”. And you will see the peasant appear.