Wednesday, February 4, 2015

Day 1: Draw a picture ( Using BlueJ )


Code: 
Square wall = new Square();
wall.makeVisible();
wall.changeSize(150);
wall.moveDown();

Square otherWall = new Square();
otherWall.makeVisible();
otherWall.changeColor("black");
otherWall.moveDown();
otherWall.moveDown();
otherWall.moveRight();
otherWall.changeSize(30);
otherWall.changeSize(50);



Triangle roof = new Triangle();
roof.makeVisible();
roof.changeSize(45, 140);
roof.moveRight();
roof.moveRight();
roof.moveright();
Error: cannot find symbol -   method moveright()
roof.moveRight();
roof.moveRight(40);
Error: method moveRight in class Triangle cannot be applied to given types;
  required: no arguments
  found: int
  reason: actual and formal argument lists differ in length
roof.moveRight();
roof.chageSize(50, 180);
Error: cannot find symbol -   method chageSize(int,int)
roof.changeSize(50, 180);
roof.moveDown();
roof.moveUp();
roof.changeSize(55, 185);

Evaluation:

  • Class - giống như 1 khuân mẫu, có các method được định sẵn, chỉ có thể sử dụng trong khoảng đã được định sẵn.
  • Object - có thể tạo được nhiều Object từ Class, nhưng mỗi Object có thể tùy chỉnh cho khác nhau đi. Tùy chỉnh bằng cách dùng các method đã đc định sẵn trong Class đó.


No comments:

Post a Comment