第十二周

1.

package khzy;
public class point {
    int x,y;
    public point(){
        
    }
    public point(int x0,int y0){
        this.x=x0;
        this.y=y0;
    }
    public String movePoint(int dx,int dy){
        x=dx+x;
        y=dy+y;
        return("("+x+","+y+")");
    }
    public static void main(String[]args){
        point p1=new point(0,0);
        point p2=new point(0,0);
        System.out.println(p1.movePoint(1,1));
        System.out.println(p2.movePoint(2,2));
    }
}

2.

package khzy;
public class Rectangle {
    /**
     * @param args
     */
     int length,width;
     public int getArea(int length,int width){
         return length*width;
     }
     public int getPer(int length,int width){
         return (length+width)*2;
     }
     public  void showAll(){
         System.out.println("长方形的长是"+length+"宽是"+width);
         System.out.println("周长是"+ (length+width)*2);
         System.out.println("面积是"+length*width);
     }
     public Rectangle(int length, int width) {
         this.length = length;
         this.width = width;
     }
     public static void main(String[] args) {
         // TODO Auto-generated method stub
         Rectangle r=new Rectangle(10, 10);
         r.showAll();
     }
}

3.

package khzy;
public class Computer {
    char colour;
    int cpu;
    public void show() {
        System.out.println("我的颜色是:" + colour+"色" + ",型号是:" + cpu);
    }
    public Computer(char colour, int cpu) {
        super();
        this.colour = colour;
        this.cpu = cpu;
    }
    public Computer() {
        super();
    }
}



package khzy;
public class test {
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Computer s1=new Computer();
        s1.colour='黑';
        s1.cpu=121;
        s1.show();
        Computer s2=new Computer('藍',111);
        s2.show();
}
}

posted @ 2021-05-25 11:53  赵佳慧  阅读(48)  评论(0编辑  收藏  举报