Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

test

  • Loading branch information...
commit 660dc84110c9b5b8aea7fc32c0c6ca68b8892eae 1 parent 932360a
@astrotycoon authored
View
BIN  Rect/Example.class
Binary file not shown
View
21 Rect/Example.java
@@ -0,0 +1,21 @@
+public class Example {
+ public static void main(String[] args) {
+ Rect rect = new Rect();
+ double w = 12.76;
+ double h = 25.28;
+
+ rect.setWidth(w);
+ rect.setHeight(h);
+
+ System.out.println("矩形对象的宽:"+ rect.getWidth() +""+ rect.getHeight());
+ System.out.println("矩形的面积:"+ rect.getArea());
+
+ System.out.println("更改向对象的方法参数传值的w,h变量的值为100和256");
+ w = 100;
+ h = 256;
+ //rect.setWidth(w);
+ //rect.setHeight(h);
+ System.out.println("矩形对象的宽:"+ rect.getWidth() +""+ rect.getHeight());
+ System.out.println("矩形的面积:"+ rect.getArea());
+ }
+}
View
BIN  Rect/Rect.class
Binary file not shown
View
30 Rect/Rect.java
@@ -0,0 +1,30 @@
+public class Rect { //创建矩形的类
+ double width;
+ double height;
+ double area;
+
+ void setWidth(double width) {
+ if (width > 0) {
+ this.width = width;
+ }
+ }
+
+ void setHeight(double height) {
+ if (height > 0) {
+ this.height = height;
+ }
+ }
+
+ double getWidth() {
+ return width;
+ }
+
+ double getHeight() {
+ return height;
+ }
+
+ double getArea() {
+ area = width * height;
+ return area;
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.