private String name = "";
private int health = 100;
private int love = 0;
private int type;
private int kind;
public String toString(){
String kind2="";
if (kind==1){
kind2="臭猪";
}
else {
kind2="骚猪";
}
String srt = "宠物的自白"+"我的名字叫"+name+","+"健康值是"+health+"和主人的亲密度是"+love+","+"我是一只"+kind2;
return srt;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getHealth() {
return health;
}
public void setHealth(int health) {
this.health = health;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public int getKind() {
return kind;
}
public void setKind(int kind) {
this.kind = kind;
}
dog dog = new dog();
Scanner scanner = new Scanner(System.in);
System.out.println("输入宠物的名字");
String name = scanner.next();
dog.setName(name);
System.out.println("选择宠物的类型:1.猪 2.企鹅");
int type=scanner.nextInt();
if (type==1){
System.out.println("选择狗的品种:1.臭猪 2.骚猪");
int kind =scanner.nextInt();
dog.setKind(kind);
System.out.println(dog);
}
else {
System.out.println("企鹅");
}
public class ddd {
int age;
ddd getAge()
{
age++;
return this;
}
public void sr()
{
System.out.println(age);
}
public static void main(String[] args) {
ddd w = new ddd();
w.getAge().getAge().getAge().sr();
}
}