TwoArea
来源:互联网 发布:淘宝小二布置的作业 编辑:程序博客网 时间:2024/06/04 01:00
/*定义一个类Point*/class Point {public int x;public int y;public Point(){this.x = 0;this.y = 0;}public Point(int x,int y){this.x=x;this.y=y;}}/*定义一个类Graph*/class Graph{public int width=0;public int height=0;public Point origin;public Graph(){origin=new Point(0,0);}public Graph(Point p){origin = p;}public Graph(Point p,int w,int h){origin=p;width=w;height=h;}public void move1(int x, int y){origin.x=x;origin.y=y;}public void move2(int a,int b){origin.x+=a;origin.y+=b;}public int area(){return width * height;}}public class TwoArea{public static void main(String args[]){int x =3,y = 4;int w =4,h = 5;Point p1 = new Point(x,y);Point p2 = new Point(6,8);Graph r1 = new Graph(p1,w,h);/*以点p1为原点,长为w,高为h画矩形r1*/Graph r2 = new Graph(p2,8,10);/*以点p2为原点,长为8,高为10画矩形r2*/r1.move1(4,6);r2.move2(-2,4);System.out.println("两个矩形面积差= "+(r2.area()-r1.area()));/*调用成员方法计算矩形r2与r1面积差*/System.out.print("r1的原点为(" +r1.origin.x+ ",");System.out.print(r1.origin.y+")");System.out.print("r2的原点为(" +r2.origin.x+",");System.out.print(r2.origin.y+"}");}}
0 0
- TwoArea
- js多张图片组成gif效果
- cvc-complex-type.2.4.d: Invalid content was found starting with element 'cim:Powersupply'.
- Android中shape的使用
- CreateFileMapping用法
- volatile and transient
- TwoArea
- ARM中的异常机制介绍
- 对象的使用
- 关于java中的hashCode()方法
- CCRect
- c++ BYTE、WORD与DWORD类型
- 操作系统中堆和栈的区别
- hdu 4607 Park Visit 求树的直径
- VS2005+VTK读入点云文件