Created
January 13, 2017 05:53
-
-
Save YaoC/05a6c8bc2ff8999fa4ef22626770fab3 to your computer and use it in GitHub Desktop.
Rectangle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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