java编写cat类,数据成员包猫的名称,体重,年龄,毛色属种,成员方法包括吃东西,睡觉,玩东西
时间: 2024-06-01 10:10:55 浏览: 15
public class Cat {
private String name;
private double weight;
private int age;
private String coatColor;
public Cat(String name, double weight, int age, String coatColor) {
this.name = name;
this.weight = weight;
this.age = age;
this.coatColor = coatColor;
}
public void eat() {
System.out.println(name + " is eating.");
}
public void sleep() {
System.out.println(name + " is sleeping.");
}
public void play() {
System.out.println(name + " is playing.");
}
public String getName() {
return name;
}
public double getWeight() {
return weight;
}
public int getAge() {
return age;
}
public String getCoatColor() {
return coatColor;
}
}