java第十二次作业

 

 

 1.

package zy;

public class test1 {
        int x;
        int y;

        test1() {

        }

        test1(int x0, int y0) {
            this.x = x0;
            this.y = y0;
        }

        public void movePoint(int dx, int dy) {
            this.x += x;
            this.y += y;
            System.out.println("坐标" + this.x + "," + this.y);
        }
        public static void main(String[] args) {
            
            test1 p1 = new test1(1,1);
            test1 p2 = new test1(4,5);
                p1.movePoint(p2.x,p2.y);
            }
}

 

 

2.

package zy;
import java.util.Scanner;
public class test2 {
    private int length;
    private int width;

    public void Rectangle() {
    }

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

    public int getLength(int i) {
        return length;
    }

    public int getWidth() {
        return width;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public void setWidth(int width) {
        this.width = width;
    }
    public void getArea(){
        System.out.println("面积为;"+width*length);
    }
    public void getPer(){
        System.out.println("周长为;"+(width+length)*2);
}
    public void getAll(){
        System.out.println("长度为"+length+"宽度为"+width+"面积为"+width*length+"周长为"+(width+length)*2);
}
    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        test2 r=new test2();
         System.out.println("请输入矩形长度");
         Scanner sc=new Scanner(System.in);
         int length = sc.nextInt();
         r.setLength(length);
         System.out.println("请输入矩形宽度");
         int width = sc.nextInt();
         r.setWidth(width);
     r.getAll();
     r.getArea();
     r.getPer();

     }
}

 

 

 3.

package zy;

public class test3 {
        char color;
        int cpu;
        
        void information(){
            System.out.println("笔记本颜色为:"+color+"\n笔记本的型号为:"+cpu);
        }
        
        test3(){}
        test3( char color, int cpu ){
            this.color = color;
            this.cpu=cpu;
            information();
        }
        public static void main(String[] args) {
            test3 information=new test3('a',350);
        }
}

 

 

posted @ 2021-05-23 23:23  藜莂  阅读(57)  评论(0编辑  收藏  举报