第十二次作业
1
package 第九次作业; public class Point { int x; int y; public Point(int x0, int y0) { this.x = x0; this.y = y0; } public Point() { } public void movePoint(int dx, int dy) { this.x += dx; this.y += dy; } public static void main(String[] args) { Point p1 = new Point(6,2); p1.movePoint(3, 6); System.out.println("p1X的坐标为:" + p1.x + " " + "p1Y的坐标为:" + p1.y); Point p2 = new Point(6, 2); p2.movePoint(6, 3); System.out.println("p2X的坐标为:" + p2.x + " " + "p2Y的坐标为:" + p2.y); } }
2
public class Rectangle { int length; int width; public int getArea(int length,int width){ return length*width; } public int getPer(int length,int width){ return (length+width)*2; } public void showAll(){ System.out.println("矩形的长是"+length+"矩形的宽是"+width+"周长是"+(length+width)*2+"面积是"+length*width); } public Rectangle(int length, int width) { super(); this.length = length; this.width = width; } public static void main(String[] args) { // TODO Auto-generated method stub Rectangle r=new Rectangle(8, 6); r.showAll(); } }
3.
package 第九次作业; public class bjb { char coulour; int cpu; public void show() { System.out.println("笔记本颜色是" + coulour + "色" + ",型号是" + cpu); } public bjb(char coulour, int cpu) { super(); this.coulour = coulour; this.cpu = cpu; } public bjb() { super(); } }
public class bjb1 { public static void main(String[] args) { // TODO Auto-generated method stub bjb a = new bjb(); a.coulour = '红'; a.cpu = 9; a.show(); bjb a1 = new bjb('白', 7); a1.show(); } }