Java第十二次作业

1.

package homework;

public class Point {

    int x;
    int y;

    public Point() {
        super();
    }

    public Point(int x0, int y0) {
        super();
        this.x = x0;
        this.y = y0;
    }

    public String movePoint(int dx, int dy) {
        x = dx + x;
        y = dy + y;
        return ("x为" + x + " y为" + y);
    }
  

        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Point p1 = new Point(6,7);
            System.out.println(p1.movePoint(6,4));
            Point p2 = new Point(4, 6);
            System.out.println(p2.movePoint(3, 7));
        }
    }

 

 

2.

package homework;

public class Rectangle {
    
      int length;
        int width;

        public Rectangle(int length, int width) {
            super();
            this.length = length;
            this.width = width;
        }

        public void getArea() {
            int sum1;
            sum1 = length * width;
            System.out.println("面积" + sum1);
        }

        public void getPer() {
            int sum2 = (length + width) * 2;
            System.out.println("周长" + sum2);
        }

        public void showAll() {
            System.out.println("长方形的长" + length + " 宽" + width);

        }

        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Rectangle r = new Rectangle(20, 5);
            r.showAll();
            r.getArea();
            r.getPer();
        }

}

 

 

3.

package homework;

public class Computer1 {
    char color;
    int cpu;

    public void show() {
        System.out.println("笔记本颜色是" + color + "色" + " 型号是" + cpu);
    }

    public Computer1(char color, int cpu) {
        super();
        this.color = color;
        this.cpu = cpu;
    }

    public Computer1() {
        super();
    }

}





public class Computer2 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Computer1 c = new Computer1();
        c.color = '黄';
        c.cpu = 44;
        c.show();
        Computer1 c1 = new Computer1('红', 88);
        c1.show();

    }

}

 

posted @ 2021-05-24 22:05  MaLD  阅读(36)  评论(0编辑  收藏  举报