public class textPet {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("欢迎来到宠物店!");
System.out.println("请输入领养宠物的名字:");
String name = scanner.next();
System.out.println("请输入领养宠物的类型:(1.狗 ,2.企鹅):");
int type = scanner.nextInt();
if (type == 1){
System.out.println("选择狗的品种:1.拉布拉多 ,2. 雪纳瑞");
int kind = scanner.nextInt();
Pet dog = new Pet(name,type,kind);
System.out.println("宠物的自白:");
String info = dog.toString();
System.out.println(info);
}
else {
System.out.println("选择企鹅性别");
int sex = scanner.nextInt();
Penguin penguin = new Penguin(name,type,sex);
System.out.println("宠物的自白:");
String info = penguin.toString();
System.out.println(info);
}
}
}
public class Penguin {
private String mName;
private int mType;
private int mKind;
private int mHealth = 100;
private int mLove = 0;
private int mSex;
public Penguin(String name, int type, int sex) {
this.mName = name;
this.mType = type;
this.mSex = sex;
}
public String toString() {
String str = "我的名字叫"+mName+","+"健康值是"+mHealth+","+
"和主人的亲密度是"+mLove+"性别是";
if (mSex == 1){
str += "Q仔";
}
else {
str += "Q妹";
}
return str;
}
public class Dog {
private String mName = "旺旺";
private int mType ;
private int mKind ;
private int mHealth = 100;
private int mLove = 0;
public Dog(String name, int type, int kind){
this.mName = name;
this.mType = type;
this.mKind = kind;
}
public String toString(){
String str = "我的名字叫"+mName+","+"健康值是"+mHealth+"和主人的亲密度是"+
mLove+"我是一只";
if (mKind == 1){
str += "拉布拉多" ;
}
else {
str += "雪纳瑞";
}
return str;
}
public String getmName() {
return mName;
}
public void setmName(String mName) {
this.mName = mName;
}
public int getmType() {
return mType;
}
public void setmType(int mType) {
this.mType = mType;
}
public int getmKind() {
return mKind;
}
public void setmKind(int mKind) {
this.mKind = mKind;
}
public int getmHealth() {
return mHealth;
}
public void setmHealth(int mHealth) {
this.mHealth = mHealth;
}
public int getmLove() {
return mLove;
}
public void setmLove(int mLove) {
this.mLove = mLove;
}
}