Java第十次作业
1.
package java10; 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,2); Point p2=new Point(3,4); p1.movePoint(p2.x, p2.y); } }
2.
package bbc; 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(2,3); a.getArea(); a.getPer(); a.getClass(); } }
3.
package java10; 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; } } package java10; public class test1 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub nextbook b=new nextbook(); b.color='红'; b.cpu=3; b.show(); }