11.日java作业

1

class XiyoujiRenwu {
    float height,weight;
    String head, ear;
    void speak(String s) {
        System.out.println(s);
    }
}
public class Ex4_1 {
    public static void main(String args[]) {
        XiyoujiRenwu zhubajie,sunwukong;
        zhubajie = new XiyoujiRenwu();
        sunwukong = new XiyoujiRenwu();
    }
}

2

package Example11月4日作业;

public class Ex4_2 {
    public static void main(String args[]) {
       XiyoujiRenwu zhubajie = null,sunwukong = null;
       zhubajie = new XiyoujiRenwu();
       sunwukong = new XiyoujiRenwu();
       zhubajie.name = PersonName.八戒;
       zhubajie.height = 1.83f;
       zhubajie.weight = 86f;
       zhubajie.head = "猪头";
       sunwukong.name = PersonName.悟空;
       sunwukong.height = 1.66f;
       sunwukong.head = "猴头";
       System.out.println(zhubajie.name + "的身高:" + zhubajie.height);
       System.out.println(zhubajie.name + "的体重:" + zhubajie.weight);
       System.out.println(zhubajie.name + "的头:" + zhubajie.head);
       System.out.println(sunwukong.name + "的身高:" + sunwukong.height);
       System.out.println(sunwukong.name + "的身高:" + sunwukong.weight);
       System.out.println(zhubajie.name + "的头:" + sunwukong.head);
       zhubajie.speak(zhubajie.name + "我想娶媳妇");
       System.out.println(zhubajie.name + "我现在的头:" + zhubajie.head);
       sunwukong.speak(sunwukong.name + "我重" +
                        sunwukong.weight + "公斤,想骗八戒背我");
       System.out.println(sunwukong.name + "现在的头:" + sunwukong.head);
    }
}

3

package Example11月4日作业;

class Point {
    int x,y;
    void setXY(int m,int n) {
        x = m;
        y = n;
    }
}
public class Ex4_3 {
    public static void main(String args[]) {
        Point p1,p2;
        p1 = new Point();
        p2 = new Point();
        System.out.println("p1的引用:" + p2);
        System.out.println("p2的引用:" + p2);
        p1.setXY(1111,2222);
        p2.setXY(-100,-200);
        System.out.println("p1的x,y坐标:" + p1.x + "," + p2.y);
        System.out.println("p2的x,y坐标:" + p2.x + "," + p2.y);
        p1 = p2;
        System.out.println("将p2的引用赋给p1后:");
        System.out.println("p1的引用:" + p1);
        System.out.println("p2的引用:" + p2);
        System.out.println("p1的x,y坐标:" + p1.x + "," + p2.y);
        System.out.println("p2的x,y坐标:" + p2.x + "," + p2.y);
    }
}

4

package Example11月4日作业;

public class Ex4_4 {
    public static void main(String args[]) {
        Rect rect = new Rect();
        double w = 12.76,h = 25.28;
        rect.setWidth(w);
        rect.setHeight(h);
        System.out.println("矩形对象的宽:" + rect.getWidth() + "高:" + rect.getHeight());
        System.out.println("矩形的面积:" + rect.getArea());
        System.out.println("更改向对象的方法参数传递值的w、h变量的值为100和256");
        w = 100;
        h = 256;
        System.out.println("矩形对象的宽:" + rect.getWidth() + "高:" + rect.getHeight());
    }
}

5

package Example11月4日作业;

public class Ex4_6_1 {
    public double getResult(double a,int ... x) {
        double  result = 0;
        int sum = 0;
        for(int i = 0;i < x.length;i ++ ) {
            sum = sum + x[i];
        }
        result = a * sum;
        return result;
    }
}
package Example11月4日作业;

public class Ex4_6_2 {
    public static void main(String args[]) {
        Computer computer = new Computer();
        double result = computer.getResult(1.0/3,10,20,30);
        System.out.println("10,20,30的平均数:" + result);
        result = computer.getResult(1.0/6,66,12,5,89,2,51);
        System.out.println("66,12,5,89,2,51的平均数:" + result);
    }
}

6

package Example11月4日作业;

public class Ex4_8 {
    double 上底,高;
    void 设置上底 (double a) {
        上底 = a;
    }
    void 设置下底(double b) {
        下底 = b;
    }
    double 获取上底() {
        return 上底;
    }
    double 获取下低() {
        return 下底;
    }
}
package Example11月4日作业;

public class Ex4_9 {
    public static void main(String args[]) {
        Ladder.下底 = 100;
        Ladder ladderOne = new Ladder();
        Ladder ladderTwo = new Ladder();
        ladderOne.设置上底(28);
        ladderTwo.设置上底(66);
        System.out.println("ladderOne的上底:" + ladderOne.获取上底());
        System.out.println("ladderOne的下底:" + ladderOne.获取下底());
        System.out.println("ladderTwo的下底:" + ladderTwo.获取上底());
        System.out.println("ladderTwo的下底:" + ladderTwo.获取下底());
    }
}

7

package Example11月4日作业;

class A {
    int x,y,z;
    static int getContinueSum(int start,int end) {
        int sum = 0;
        for(int i = start;i <= end;i++ ) {
            sum = sum + i;
        }
        return sum;
    }
}
public class Ex4_9 {
    public static void main(String args[]) {
        int result = A.getContinueSum(0,100);
        System.out.println(result);
    }
}

8

package Example11月4日作业;

public class EX4_10 {
    int leg,hand;
    String name;
    People(String s) {
        name = s;
        this.init();
    }
    void init(){
        leg = 2;
        hand = 2;
        System.out.println(name + "有" + hand + "只手" + leg + "条腿");
    }
    public static void main(String args[]){
        People boshi = new People("布什");
    }
}

9

package Example11月4日作业;

public class Ex4_16 {
    private int money;
    private int getMoney() {
        return monry;
    }
    public static void main(String args[]){
        AAA exa = new AAA();
        exa.money = 3000;
        int m = exa.getMoney();
        System.out.println("money =" + m);
    }
}

10

package Example11月4日作业;

public class Ex4_17 {
    public static void main(String args[]) {
        Student zhang = new Student();
        Student geng = new Student();
        zhang.setAge(23);
        System.out.println("zhang的年龄:" + zhang.getAge());
        geng.setAge(25);
        System.out.pintln("geng的年龄:" + geng.getAge());
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值