课后题168页-1

package org.hanqi.pn0120;

public class Dog {

        //尝试编写一个类,定义一个修饰权限为private的成员变量,
        //定义两个成员方法,一个方法实现为此成员变量赋值,
        //另一个成员方法获取这个成员变量的值,保证其他类继承该类时能获取该类的成员变量的值。

    //品种
    private String type;
    //年龄
    private int age;
    //颜色
    private String color;
    //重量
    private double weight;
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    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 Dog(String type, int age, String color, double weight) {
        super();
        this.type = type;
        this.age = age;
        this.color = color;
        this.weight = weight;
    }
    public void texing(double weight)
    {
        if(weight<70)
        {
            System.out.println("您的狗狗偏瘦,处于亚健康状态");
        }
        else if(weight>100)
        {
            System.out.println("您的狗狗过于肥胖,请及时锻炼");
        }
        else
        {
            System.out.println("体重正常,符合达标");
        }
    }
    
    public static void main(String[] args)
    {
        Dog myAlasijia=new Dog("阿拉斯加",2,"黑白",95);
        System.out.println("品种="+myAlasijia.getType());
        System.out.println("年龄="+myAlasijia.getAge());
        myAlasijia.texing(80);
        System.out.println("当前状况为:"+myAlasijia.getWeight());
    }

texing定义无效,希望老师指点。

原文地址:https://www.cnblogs.com/cycanfly/p/5249178.html