Skip to content

Instantly share code, notes, and snippets.

@YaoC
Created January 13, 2017 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YaoC/05a6c8bc2ff8999fa4ef22626770fab3 to your computer and use it in GitHub Desktop.
Save YaoC/05a6c8bc2ff8999fa4ef22626770fab3 to your computer and use it in GitHub Desktop.
Rectangle
/**
* Created by chengyao on 2017/1/12.
*/
public class Main {
public static void main(String[] args) {
Rectangle rect = new Rectangle(1, 3, 2.5, 4);
System.out.println("长方形的位置:("+rect.getX()+","+rect.getY()+"),面积为:"+rect.getArea());
rect = new Rectangle(3, 5, 4, 8);
System.out.println("现在长方形的位置:("+rect.getX()+","+rect.getY()+"),面积为:"+rect.getArea());
}
}
/**
* Created by chengyao on 2017/1/13.
*/
public class Rectangle {
private double x;
private double y;
private double width;
private double length;
public Rectangle(double x, double y, double width, double length) {
this.x = x;
this.y = y;
this.width = width;
this.length = length;
}
public Rectangle() {
this.x = 0;
this.y = 0;
this.width = 0;
this.length = 0;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public double getWidth() {
return width;
}
public double getLength() {
return length;
}
public double getArea(){
return width * length;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment