Skip to content

Instantly share code, notes, and snippets.

@behitek
Created November 3, 2016 12:46
Show Gist options
  • Save behitek/d2573ba65a30c0884f56f2bae44a9aeb to your computer and use it in GitHub Desktop.
Save behitek/d2573ba65a30c0884f56f2bae44a9aeb to your computer and use it in GitHub Desktop.
Viết chương trình mô tả đối tượng Rectangle
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package BT2;
/**
*
* @author HieuNguyen
*/
public class Rectangle {
private int width;
private int height;
public Rectangle() {
}
public Rectangle(int width, int height) {
this.width = width;
this.height = height;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getArea(){
return width*height;
}
public int getPerimeter(){
return (width + height)*2;
}
public void display(){
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
System.out.print("#");
}
System.out.println("");
}
}
public static void main(String[] args) {
Rectangle r = new Rectangle(3,7);
r.display();
r.setWidth(5);
r.setHeight(6);
System.out.println("Perimeter : "+r.getPerimeter()+"\nArea: "+r.getArea());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment