//属性和方法
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();
}