首页 > 编程语言 > 详细

java第十二周作業

时间:2021-05-25 09:19:22      阅读:13      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

 

package 第十二周;

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));
    }

}

技术分享图片技术分享图片

package 第十二周;

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();
        
        }

}技术分享图片

技术分享图片

 

 

package 第十二周;

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 第十二周;

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();
 }
}

技术分享图片

 

java第十二周作業

原文:https://www.cnblogs.com/1anff/p/14806855.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!