实现领养宠物的功能
1.模块1(Dog对象):
public class Dog {
String name;
String strainStr;
String heatlthStr;
String loveStr;
}
2.模块2(Penguin对象):
public class Penguin {
String name;
String sexStr;
String heatlthStr;
String loveStr;
}
3.测试:
public class Text {
public static void main(String[] args) {
System.out.println("****************欢迎您来到宠物店!************");
System.out.println("请输入要领养宠物的名字:");
Scanner scanner=new Scanner(System.in);
String name=scanner.next();
System.out.println("请选择要领养的宠物类型:(1、狗狗 2、企鹅)");
int type=scanner.nextInt();
if(type==1){
System.out.println("请选择狗狗的品种:(1、聪明的拉布拉多犬 2、酷酷的雪纳瑞)");
int strain=scanner.nextInt();
String strainStr="";
if(strain==1){
strainStr="聪明的拉布拉多犬";
}else if(strain==2){
strainStr="酷酷的雪纳瑞";
}
System.out.println("请输入狗狗的健康值:");
String healthStr=scanner.next();
System.out.println("请输入狗狗的亲密度:");
String love=scanner.next();
System.out.println("宠物的自白:");
Dog dog=new Dog();
dog.name=name;
dog.strainStr=strainStr;
dog.heatlthStr=healthStr;
dog.loveStr=love;
System.out.println("我的名字是"+dog.name+",健康值是"+dog.heatlthStr+",和主人的亲密度是"
+dog.loveStr+".我是一只"+dog.strainStr);
}else if(type==2){
System.out.println("请输入企鹅的性别:(1.Q仔 2.Q妹)");
int sex=scanner.nextInt();
String sexStr="";
if(sex==1){
sexStr="Q仔";
}else if(sex==2){
sexStr="Q妹";
}
System.out.println("请输入企鹅的健康值:");
String healthStr=scanner.next();
System.out.println("请输入企鹅的亲密度:");
String love=scanner.next();
System.out.println("宠物的自白:");
Penguin penguin=new Penguin();
penguin.name=name;
penguin.sexStr=sexStr;
penguin.heatlthStr=healthStr;
penguin.loveStr=love;
System.out.println("我的名字是"+ penguin.name+",健康值是"+ penguin.heatlthStr+",和主人的亲密度是"
+ penguin.loveStr+",性别是"+ penguin.sexStr);
}
}
}
4.结果: