第十次作业

1

package sc;

public class point {
    int x;
    int y;
    public point(int x0,int y0){
        super();
        this.x=x0;
        this.y=y0;
    }
    public point(){
        super();
    }
    public String movepoint(int dx,int dy){
        x+=dx;
        y+=dy;
        return ("x为"+x+"  y为"+y);
    }
    public static void main(String[] args) {
           point p1 = new point(5, 2);
           System.out.println(p1.movepoint(9, 4));
           point p2 = new point(49, 3);
           System.out.println(p2.movepoint(6, 6));
          
    }

    
    

}

 

 

   

2

package sc;

public class Rectangle {

    int length;
    int width;
public int getArea(int lenght,int width){
    return length*width;
}
public int getPer(int length,int width){
    return (length+width)*2;
}
public void showAll(){
    System.out.println("长"+length+  " 宽"+width+  " 周长"+(length+width)*2+  " 面积"+length*width   );
}
public Rectangle(int length,int width){
    super();
    this.length=length;
    this.width=width;
    

}

    public static void main(String[] args) {
        Rectangle b=new Rectangle(5,9);
        b.showAll();
        

    }

}

      

 

 

3

package sc;

public class computer {
    char color;
    int cpu;
    public void show(){
        System.out.println("颜色"+color+"型号"+cpu );
    }
    public computer (char color,int cpu){
        super();
        this.color=color;
        this.cpu=cpu;
    }
    public computer(){
        super();
    }
    public static void main(String[] args) {
        computer a=new computer();
        a.color='黑';
        a.cpu=111;
        a.show();
        computer b=new computer('白',1134);
        b.show();

    }

}

posted @ 2021-05-25 15:58  宋驰  阅读(46)  评论(0编辑  收藏  举报