宠物管理系统

//属性和方法

private String name;
    private String sex;
    private int lovely;
    private int health;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getSex() {
        return sex;
    }
    public void setSex(String sex) {
        this.sex = sex;
    }
    public int getLovely() {
        return lovely;
    }
    public void setLovely(int lovely) {
        if(lovely>=0&& lovely<=100){
            this.lovely = lovely;
        }else{
            this.lovely=60;
        }
        
    }
    public int getHealth() {
        return health;
    }
    public void setHealth(int health) {
        if(health>=0&& health<=100){
            this.health = health;
        }else{
            this.health=60;
        }
    }
    public void show(){
        System.out.println("我的名字是:"+this.name+"健康值是:"+health+
                "亲密度是"+lovely+"我的性别是"+sex);
    }

 //代码

    System.out.println("欢迎来到宠物系统");
    System.out.println("请输入想要领养的宠物的名字");
    Scanner sc=new Scanner(System.in);
    String name=sc.next();
    Penguin pen=new Penguin();    
    pen.setName(name);    
    System.out.println("请输入企鹅性别");
    int sex=sc.nextInt();
    if(sex==1){
        pen.setSex("Q妹");
    }else{
        pen.setSex("Q仔");
    }
    System.out.println("请输入企鹅的健康值(0-100之间)");
    int heal= sc.nextInt();
    pen.setHealth(heal);
    System.out.println("请输入企鹅的亲密度(0-100之间)");
    int lov= sc.nextInt();
    pen.setLovely(lov);
    pen.show();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值