Java第十二周作业
public class Point { int x; int y; public Point(){ } public Point(int x0,int y0){ this.x=x0; this.y=y0; } public void movePoint(int dx,int dy){ x=x+dx; y=y+dy; System.out.println("移动后坐标:"+x+","+y); } public static void main(String[] args) { Point p1=new Point(1,1); Point p2=new Point(2,2); p1.movePoint(1,1); p2.movePoint(1,1); } }
package j1; public class Rectangle { int length; int width; Rectangle(int length,int width){ this.length=length; this.width=width; } void showAll(){ System.out.println("长是"+length+"宽是"+width); } void getPer(){ System.out.println("周长"+2*(length+width)); } void getArea(){ System.out.println("面积"+length*width); } public static void main(String[] args) { Rectangle A=new Rectangle(3,4); A.getArea(); A.getPer(); A.showAll(); } }
public class nextbook { char color; int cpu; public void show(){ System.out.println("颜色:"+color+" 型号:"+cpu); } public int cpu(){ return cpu; } public char color(){ return color; } }
public class test1 { public static void main(String[] args) { nextbook A=new nextbook(); A.color='蓝'; A.cpu=2; A.show(); } }