码迷,mamicode.com
首页 > 其他好文 > 详细

第九周上机练习

时间:2020-04-30 15:47:53      阅读:55      评论:0      收藏:0      [点我收藏+]

标签:system   int   poi   move   val   pack   code   bsp   color   

1.

package LH;
public class Point {
        int x;
        int y;

        Point() {

        }

        Point(int x0, int y0) {
            this.x = x0;
            this.y= y0;
        }
        
        void movePoint(int dx,int dy) {
            this.x += dx;
            this.y += dy;
            
        }
    }
package LH;
public class Test {
    public static void main(String[] args) {
        Point p1 = new Point(1, 1);
        p1.movePoint(2, 2);
        System.out.println("p1当前的X坐标为:" + p1.x + ",p1当前的Y坐标为:" + p1.y);
        Point p2 = new Point(1,1);
        p2.movePoint(3, 3);
        System.out.println("p2当前的X坐标为:" + p2.x + ",p2当前的Y坐标为:" + p2.y);

    }
}

2.

package LH;

public class Rectangle {
    int length;
    int width;

    public void getArea() {
        System.out.println(length * width);
    }

    public void getPer() {
        System.out.println((length + width) * 2);
    }

    public void showAll() {
        System.out.println("长:" + length);
        System.out.println("宽:" + width);
        System.out.print("面积:");
        getArea();
        System.out.print("周长:");
        getPer();
    }

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

}
package LH;

public class Text {
    public static void main(String[] args) {
        Rectangle rc = new Rectangle(3, 5);
        rc.showAll();
    }
}

3.

package LH;

public class Com {
       char color;
        String cpu;
        public bjb() {
            System.out.println("无参数");
        }
        public bjb(char a,String b) {
            color=a;
            cpu=b;
            System.out.println(color);
            System.out.println(cpu);
            System.out.println("有参数");
        }
        public void sj(){
            System.out.println("颜色是"+color);
            System.out.println("cpu"+cpu);
        } 
}
package LH;

public class Test {
    public static void main(String[] args) {
            bjb b1=new  bjb();
            bjb b2=new  bjb(‘白‘,"i7");
            b2.sj();
        }

    }

6.

package LH;

public class Preson {
        String name;
        int age;
        double height;
        public void sayHello(){
            System.out.println("hello,my name is "+this.name);
        }
        public void getValue(String name,int age,double height){
            this.name = name;
            this.age = age;
            this.height = height;
        }
    }
package LH;

public class Test {

    public static void main(String[] args) {
        Person p1 = new Person();
        p1.getValue("zs",25,1.85);
        p1.sayHello();
        Person p2 = new Person();
        p2.getValue("ls",35,1.75);
        p2.sayHello();
        }
    }

 

第九周上机练习

标签:system   int   poi   move   val   pack   code   bsp   color   

原文地址:https://www.cnblogs.com/z118127/p/12808819.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!