Java程序第十次作业

package com.homework08;

public class Point {
    public int x;
    public int y;
    public Point() {
        x = 0;
        y = 0;
    }
    public Point(int x0, int y0) {
        x = x0;
        y = y0;
    }
    public void movePoint(int dx, int dy) {
        x += dx;
        y += dy;
    }
}

package com.homework08;

public class Assignment01 {
    public static void main(String[] args) {
        Point point = new Point(0, 0);
        System.out.print(point.x + " " + point.y + "\n");
        point.movePoint(7, 7);
        System.out.print(point.x + " " + point.y + "\n");
    }
}

package com.homework08;

public class Rectangle {
    public Rectangle(float aLength, float aHeight) {
        length = aLength;
        height = aHeight;

    }
    float getArea() {
        return length * height;
    }
    float getPer() {
        return (length + height) * 2;
    }
    void showAll() {
        System.out.println(length);
        System.out.println(height);
        System.out.println(getArea());
        System.out.println(getPer());
    }

    float length;
    float height;
}

package com.homework08;

public class Assignment02 {
    public static void main(String[] args) {
        Rectangle rectangle = new Rectangle(7, 7);

        rectangle.showAll();
    }
}

package com.homework08;

public class Laptop {
    Laptop() {
        color = '黑';
        model = 1000;
    }
    Laptop(char aColor, int aModel) {
        color = aColor;
        model = aModel;
    }
    void printInformation() {
        System.out.println("color :" + color);
        System.out.println("model :" + model);
    }
    char color;
    int model;
}







package com.homework08;

public class Assignment03 {
    public static void main(String[] args) {
        Laptop laptop = new Laptop('黑', 5470);
        laptop.printInformation();
        Laptop laptopB = new Laptop();
        laptopB.printInformation();
    }
}

posted @ 2021-05-26 13:52  SuoJing  阅读(30)  评论(0编辑  收藏  举报