Java第十次作业
1.
package work; import work.Point; public class test { public static void main(String[] args) { Point x1 = new Point(3.0, 5.5); Point x2 = new Point(); x1.movePoint(); x2.movePoint(); } } class Point { double a; double b; public Point() { super(); } public Point(double a, double b) { this.a = a; this.b = b; } public void movePoint() { System.out.println("点的坐标为"); System.out.println(+a + "," + b); } }
2.
package work; import work.Rectangle; public class test1 { public static void main(String[] args) { Rectangle a = new Rectangle(3, 4); a.getArea(); a.getPer(); a.showAll(); } } class Rectangle { int l; int w; public Rectangle(int dw, int dl) { super(); w = dw; l = dl; } public void getArea() { int Area = w * l; System.out.println("面积是" + Area); } public void getPer() { int Per = (w + l) * 2; System.out.println("周长是" + Per); } public void showAll() { int Area = w * l; int Per = (w + l) * 2; System.out.println("长是" + l + "宽是" + w + "面积是" + Area + "周长是" + Per); } }
3.
package work; import work.notebook; public class test3 { public static void main(String[] args) { // TODO Auto-generated method stub notebook a = new notebook('红', 9888); 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 + ""); } }