Thứ Hai, 8 tháng 6, 2015

AP Lab 3: Lập trình hướng đối tượng

Một cách giản lược, Lập trình hướng đối tượng - OOP  là một nỗ lực nhằm giảm nhẹ các thao tác viết mã cho người lập trình, cho phép họ tạo ra các ứng dụng mà các yếu tố bên ngoài có thể tương tác với các chương trình đó giống như là tương tác với các đối tượng vật lý.
Những đối tượng trong một ngôn ngữ OOP là các kết hợp giữa mã và dữ liệu mà chúng được nhìn nhận như là một đơn vị duy nhất. Mỗi đối tượng có một tên riêng biệt và tất cả các tham chiếu đến đối tượng đó được tiến hành qua tên của nó. Như vậy, mỗi đối tượng có khả năng nhận vào các thông báo, xử lý dữ liệu (bên trong của nó), và gửi ra hay trả lời đến các đối tượng khác hay đến môi trường.

+ Abstraction (Trừu tượng hóa):  Là 1 kĩ thuật chỉ trình bày những đặc điểm cần thiết  của vấn đề mà không cần thiết phải trình bày cụ thể , phức tạp.

+ Encapsulution (Tính đóng gói): Là tiến trình che giấu việc thực thi chi tiết của 1 đối tượng.

+ Inheritance ( Tính kế thừa ): Là các phương thức hay thuộc tính đc định nghĩa trong 1 lớp có thể dc thừa kế và sử dụng trong các lớp khác.

+ Polymorphism (Tính đa hình): là "nhiều hình thức", 1 hành động cùng tên có thể dc thực hiện khác nhau đối vs các Object hay các class khác nhau.

(+) Object ( Đối tượng ): Là 1 thực thể phần mềm chứa các thuộc tính hay các phương thức liên quan.

(+) Class (Lớp): Là 1 mẫu định nghĩa các phương thức , thuộc tính chung cho các đối tượng cùng loại nào đó.

Tầm vực truy xuất:

Private : chỉ cho phép truy xuất trong nội bộ phần định nghĩa lớp đối tượng
Protected : được sử dụng cho các biến lớp dẫn xuất (kế thừa)
Public : cho phép truy xuất ở bất kì nơi nào trong chương trình.


Excercise:




Main:


Class Atom :


Thứ Tư, 3 tháng 6, 2015

AP Lab1 : C# begins!!




Các kiểu tập hợp dữ liệu chính trong C#:

  1. Kiểu xây dựng sẵn mà chương trình tạo ra cho người lập trình
  2. Kiểu người dùng tự định nghĩa:  
  • Kiểu dữ liệu giá trị (value): 1 biến được khai báo với kiểu dữ liệu này thì biến này sẽ chứa giá trị dữ liệu. VD các kiểu DLGT: int, float char , .....
  • Kiểu dữ liệu tham chiếu (reference):kiểu dữ liệu tham chiếu chỉ lưu trữ địa chỉ tham chiếu tới vùng nhớ chứa giá trị thật sự.

Excercises:

Exercise 1Write a program to enter: name, address, phone and display these information.


Exercise 2: Write a program to accept three integer number and find maximum number from three integer. 



Exercise 3: Write a program that accepts a number between 1 and 7 from the user and return the corresponding day of the week


Exercise 4: Write a program to display the first 9 multiples of an integer N entered from user
 

Exercise 5: Write a program to print the factorials of the integers from 1 to 20


Thứ Hai, 9 tháng 3, 2015

ADF1 - Inheritance

Make a documentation of this framework by declare some variables of Actor and create some objects of GoJumpActor, JumpGoActor, asign them to the above variables and call them.


Code:

  • Class Interface Moveable:
public interface Moveable
{
    public void Jump();
    
    public void Forward();
}
  • Class abstract Actor:
public abstract class Actor implements Moveable
{
    private Circle face;
    
    public Actor(){
        face = new Circle();
        face.makeVisible();
        face.changeColor("red");
        face.changeSize(50); 
    }
    
    public void Jump(){
        face.slowMoveVertical(-30);
    }
    
    public void Forward(){
        face.slowMoveHorizontal(10);
    }
}
  • Class extend GoJumpActor:
public class GoJumpActor extends Actor
{
    public void GoAndJump(){
        Forward();
        Jump();
    }
}
  • Class extend JumpGoActor:
public class JumpGoActor extends Actor
{
    public void JumpAndGo(){
        Jump();
        Forward();
    }
}

Thứ Bảy, 7 tháng 3, 2015

ADF1 - Interface

Today, game is an important industrial of software, one of most important features that a game must have is the extensible capacity. As an architect, you know the meaning of “implement into interface not into implementation”, so you must:


Create an interface for actor that can do :
- forward()
- jump()
- blink()


Code:
  • Interface:

public interface Action
{
    public void Forward();
    
    public void Blink();
    
    public void Jump();
}

  • Class Actor:
public class Actor implements Action
{
    private Circle face;
    private Circle leftEye;
    private Circle rightEye;
    private Triangle mouth;
  
    
    public Actor(){
        
        face = new Circle();
        face.makeVisible();
        face.changeSize(70);
        face.moveHorizontal(107);
        face.moveVertical(100);
        face.changeColor("yellow");
        
        leftEye = new Circle();
        leftEye.makeVisible();
        leftEye.changeSize(15);
        leftEye.moveHorizontal(120);
        leftEye.moveVertical(120);
        leftEye.changeColor("black");
        
        rightEye = new Circle();
        rightEye.makeVisible();
        rightEye.changeSize(15);
        rightEye.moveHorizontal(150);
        rightEye.moveVertical(120);
        rightEye.changeColor("black");
        
        mouth = new Triangle();
        mouth.makeVisible();
        mouth.changeSize(8,30);
        mouth.moveHorizontal(112);
        mouth.moveVertical(192);
        mouth.changeColor("brown");
    }
    
    public void Forward(){
        face.moveHorizontal(100);
        leftEye.moveHorizontal(100);
        rightEye.moveHorizontal(100);
        mouth.moveHorizontal(100);        
    }
    
    public void Jump(){
        face.moveVertical(-100);
        leftEye.moveVertical(-100);
        rightEye.moveVertical(-100);
        mouth.moveVertical(-100);
        face.moveVertical(100);
        leftEye.moveVertical(100);
        rightEye.moveVertical(100);
        mouth.moveVertical(100);
    }
    
    public void Blink(){
        face.makeInvisible();
        leftEye.makeInvisible();
        rightEye.makeInvisible();
        mouth.makeInvisible();
        
        face.moveHorizontal(100);
        leftEye.moveHorizontal(100);
        rightEye.moveHorizontal(100);
        mouth.moveHorizontal(100);
        
        face.makeVisible();
        leftEye.makeVisible();
        rightEye.makeVisible();
        mouth.makeVisible();
    }    
     
}   




Chủ Nhật, 1 tháng 3, 2015

Ep3 - Add Behavior



  • Create methods sunRise(), sunSet() for make animation for the following scenarios




Code:

/**
 * Sun
 *
 * @author (MZ)
 * @version (1.0)
 */
public class Sun
{
    private Circle sun;
    /**
     * Constructor for objects of class Sun
     */
    public Sun()
    {
       sun = new Circle();
       sun.makeVisible();
       sun.changeColor("yellow");
       sun.changeSize(50);
       sun.moveHorizontal(220);
    }
   
    public void sunSet(){
        sun.slowMoveVertical(300);
    }
   
    public void sunRise(){
       sun.slowMoveVertical(-300);
    }

}




Thứ Năm, 26 tháng 2, 2015

BuildClass-EP2


  • Create class of following images:


Code:

Class House:

/**
 * House
 *
 * @author (MZ)
 * @version (1.0)
 */
public class House
{
    private Triangle roof;
    private Square wall;
    private Square window;
    private Circle hill;

    /**
     * Constructor for objects of class House
     */
    public House()
    {
        roof = new Triangle();
        roof.makeVisible();
        roof.changeColor("green");
        roof.changeSize(50,120);
        roof.moveRight();
        roof.moveDown();
        roof.moveDown();
        roof.moveDown();
        roof.moveRight();
        roof.moveRight();
       
        wall = new Square();
        wall.makeVisible();
        wall.changeSize(100);
        wall.moveDown();
        wall.moveDown();
        wall.moveDown();
        wall.moveDown();
        wall.moveVertical(-5);
       
        window = new Square();
        window.makeVisible();
        window.moveDown();
        window.moveDown();
        window.moveDown();
        window.moveDown();
        window.changeColor("black");
        window.moveDown();
        window.moveRight();
       
        hill = new Circle();
        hill.makeVisible();
        hill.changeColor("green");
        hill.changeSize(440);
        hill.moveVertical(150);
        hill.moveLeft();
        hill.moveLeft();
        hill.moveLeft();
        hill.moveLeft();
        hill.moveLeft();
        hill.moveLeft();
    }
}

Class Sun:

/**
 * Sun
 *
 * @author (MZ)
 * @version (1.0)
 */
public class Sun
{
    private Circle sun;
    /**
     * Constructor for objects of class Sun
     */
    public Sun()
    {
       sun = new Circle();
       sun.makeVisible();
       sun.changeColor("yellow");
       sun.changeSize(50);
       sun.moveHorizontal(220);
    }

}
   


CreateObject-DrawPicture


Draw the images using tool: