4月30号作业

1.

package hello;

public class yes {
    

        private int x0;
        private int y0;
        public yes(){
        
        }
        public yes(int x0,int y0) {
            this.x0=x0;
            this.y0=y0;
        }
        public void point1(){
            System.out.println("无参构造("+x0+","+y0+")");
        }
        public void movepoint(int dx,int dy){
            System.out.println("坐标是:("+dx+","+dy+")");
        }
    }
package hello;

public class text {
public static void main(String[] args) {
yes p1=new yes();
p1.movepoint(3, 4);
yes p2=new yes();
p2.movepoint(5, 8);
yes p3=new yes(12,34);
p3.point1();
}
}

2.

package hello;

public class yes {
    
    double length;
    double 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);
        getArea();
        getPer();
    }
}
package hello;
import java.util.Scanner;
public class text {
public static void main(String[] args) {
    try (Scanner input = new Scanner(System.in)) {
        yes r = new yes();        
        System.out.println("请输入长方形的长:");
        r.length = input.nextInt();
        System.out.println("请输入长方形的宽:");
        r.width = input.nextInt();
        r.getArea();
        r.getPer();
        r.showAll();
    }
}
}

3.

package hello;

public class yes {   
    
char color;
int cpu;
yes() {

}
yes(char color, int cpu) {
    this.color = color;
    this.cpu = cpu;
}
void a() {
    System.out.println("颜色:" + color + "  型号:" + cpu);
}
}
package hello;

public class text {
public static void main(String[] args) {
    // TODO Auto-generated method stub
    yes a = new yes('s', 18928888);
    a.a();
}
}

4.

package hello;

public class Person {
    String name;// 姓名
    double height;// 身高
    double age ;// 年龄
    Person(String name, double height, double age) {
        this.name = name;
        this.height = height;
        this.age = age;
    }
    void sayHello() {
        System.out.println("hello,my name is  " + name+" "+height+"m"+" "+age+"");
    }

}
package hello;

public class text {
public static void main(String[] args) {
    // TODO Auto-generated method stub
    Person a = new Person("zhangsan", 1.73, 33);
    Person b = new Person("lishi", 1.74, 44);
    a.sayHello();
    b.sayHello();
}
}

 

posted @ 2020-04-30 12:49  射手要出宝石  阅读(154)  评论(0编辑  收藏  举报