实现领养宠物的功能(test类)

package cn.kgc.demo4;

import java.util.Scanner;

public class Test {

	public static void main(String[] args) {
	Scanner input =new Scanner(System.in);
	System.out.println("====欢迎您来到宠物店!=====");
System.out.println("请输入你要领养的宠物名字:");
String petName =input.next();
System.out.println("请选择要领养的宠物类型:(1.狗狗 2.企鹅)");
int  choice =input.nextInt();
switch (choice) {
case 1:
	Dog dog =new Dog();
	dog.setName(petName);
	System.out.println("请选择狗狗的性别:(1.雄性  2.雌性)");
	int  xingBie =input.nextInt();
	if (xingBie==1) {
		dog.setSex("雄性");
	}else {
		dog.setSex("雌性");
	}
	System.out.println("请输入狗狗的健康值(1-100之间):");
	int  healthy =input.nextInt();
	dog.setHealth(healthy);
	System.out.println(dog.showInfo());
break;
case 2:
	Peguin peguin =new Peguin();
	peguin.setName(petName);
	System.out.println("请选择企鹅的性别:(1.Q仔   2.Q妹)");
	int  xuanZe =input.nextInt();
	if (xuanZe==1) {
		peguin.setSex("Q仔");
	}else {
		peguin.setSex("Q妹");
	}
	System.out.println("请输入企鹅的健康值(1-100之间):");
	int  jianKangzhi =input.nextInt();
	peguin.setHealth(jianKangzhi);
	System.out.println(peguin.toString());
	break;
	
default:
	System.out.println("您的选择有误,请重新输入");
	break;
}

	}

}

你可能感兴趣的:(for的二重循环,switch分支结构,数组)