【无标题】

package zxs;

public class Demo3 {
    public static void main(String[] args) {
        Cat cat1=new Cat();
        cat1.setAge(2);
        cat1.setBrand("niunaimao");
        cat1.setColor("黑白色");
        cat1.setGender(true);
        cat1.setWeight(10);
        System.out.println("brand="+cat1.getBrand()+",age="+cat1.getAge()+",olor="+cat1.getColor()+",gender="+cat1.isGender()
        +",weight="+cat1.getWeight());
        if(cat1.isGender()){
            System.out.println("这个猫是母猫");

        }else{
            System.out.println("这个猫是公猫");
        }
        System.out.println("--------------");
        Cat cat2 =new Cat(age:5,brand:"英短",color:"蓝色",weight:15,gender:true,weight:9.9);
        System.out.println("brand="+cat2.getBrand()+",age="+cat2.getAge()+",olor="+cat2.getColor()+",gender="+cat2.isGender()
                +",weight="+cat2.getWeight());
        if(cat2.isGender()){
            System.out.println("这个猫是母猫");

        }else{
            System.out.println("这个猫是公猫");
        }

    }
}

package zxs;

public class Cat {
    private  int age;
    private  String brand;
    private  String color;
    private  double weight;
    private  boolean gender;



    public Cat(int age, String brand, String color, double weight, boolean gender) {
        this.age = age;
        this.brand = brand;
        this.color = color;
        this.weight = weight;
        this.gender = gender;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public boolean isGender() {
        return gender;
    }

    public void setGender(boolean gender) {
        this.gender = gender;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值