12周作业
第一题
package chap9; public class text1 { public static void main(String[] args) { Point p1 = new Point(2.0, 4.5); Point p2 = new Point(); p1.movePoint(); p2.movePoint(); } } class Point { double x; double y; public Point() { super(); } public Point(double x, double y) { this.x = x; this.y = y; } public void movePoint() { System.out.println("点的坐标为"); System.out.println(+x + "," + y); } }
第二题
package chap9; public class text2 { public static void main(String[] args) { Rectangle a = new Rectangle(4, 5); a.getArea(); a.getPer(); a.showAll(); } } class Rectangle { int length; int width; public Rectangle(int dwidth, int dlength) { super(); width = dwidth; length = dlength; } public void getArea() { int Area = width * length; System.out.println("面积为" + Area); } public void getPer() { int Per = (width + length) * 2; System.out.println("周长为" + Per); } public void showAll() { int Area = width * length; int Per = (width + length) * 2; System.out.println("长为" + length + "宽为" + width + "面积为" + Area + "周长为" + Per); } }
第三题
package chap9; public class text3 { public static void main(String[] args) { // TODO Auto-generated method stub notebook a = new notebook('黑', 9800); a.zhan(); } } class notebook { char colour; int cpu; public notebook(char colour, int cpu) { this.colour = colour; this.cpu = cpu; } public notebook() { super(); } public void zhan() { System.out.println("笔记本颜色为" + colour + "型号为" + cpu + ""); } }