public class textPet {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("歡迎來到寵物店跨蟹!");
System.out.println("請輸入領養(yǎng)寵物的名字:");
String name = scanner.next();
System.out.println("請輸入領養(yǎng)寵物的類型:(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;
}
}