package cn.jbit.output;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Manager {
Scanner input = new Scanner(System.in);
List<Pet> list = new ArrayList<Pet>();
Master ms = null;
//初始化
public void initail() {
//实例化宠物
Dog dog1= new Dog("哈哈",80,90,"哈士奇");
Dog dog2= new Dog("拉拉",70,70,"金毛");
Dog dog3= new Dog("豆豆",95,80,"黑背");
Penguin pen1=new Penguin("贝贝",80,90,"Q仔");
Penguin pen2=new Penguin("蕊蕊",90,70,"Q妹");
list.add(dog1);
list.add(dog2);
list.add(dog3);
list.add(pen1);
list.add(pen2);
//创建主人对象
ms = new Master("张三","123456",2000);
}
/**
* 项目启动
*/
public void start() {
initail(); //项目启动时,调用初始化的方法,加载数据
do {
System.out.println("************欢迎来到宠物商店管理系统************");
System.out.println("1.用户登录");
System.out.println("2.退出系统");
System.out.println("请输入:");
int choose = input.nextInt();
switch (choose) {
case 1 :
MasterLogin();
break;
case 2 :
System.out.println("谢谢使用");
break;
}
}while(true);
}
//主人登录
public void MasterLogin(){
System.out.println("请输入用户名");
String user = input.next();
System.out.println("请输入密码");
String pwd = input.next();
if (user.equals(ms.getName()) && pwd.equals(ms.getPwd())) {
System.out.println( "欢迎"+ms.getName()+"登录,您的余额是:"+ms.getMoney());
do {
System.out.println("1.查看所有的宠物信息");
System.out.println("2.按照宠物昵称查询宠物");
System.out.println("3.按照宠物类别查询宠物");
System.out.println("4.添加宠物");
System.out.println("5.修改宠物信息");
System.out.println("6.删除宠物");
System.out.println("7.退出系统");
System.out.println("请选择:");
int xuan = input.nextInt();
switch(xuan){
case 1:
getAllPet();
break;
case 2:
getPetByName();
break;
case 3:
getPetByType();
break;
case 4:
addPet();
break;
case 5:
break;
case 6:
deletePet();
break;
case 7:
break;
}
}while(true);
}else{
System.out.println("用户名或密码错误");
}
}
//1.查看所有宠物
public void getAllPet() {
for (Pet pet:list) {
if (pet instanceof Dog) {
Dog dog = (Dog)pet;
pet.show();
} else if(pet instanceof Penguin) {
Penguin pen =(Penguin)pet;
pet.show();
}
}
}
//2.按照昵称查询
public void getPetByName(){
System.out.println("请输入宠物昵称");
String name = input.next();
for(Pet pet:list) {
if(name.equals(pet.getName())) {
pet.show();
}
}
}
//3.按照类别查询宠物
public void getPetByType(){
System.out.println("请选择类别(1.狗狗类 2.企鹅类)");
int choose = input.nextInt();
switch (choose) {
case 1:
for (Pet pet : list) {
if(pet instanceof Dog){
pet.show();
}
}
break;
case 2:
for (Pet pet : list) {
if(pet instanceof Penguin){
pet.show();
}
}
break;
}
}
//4.添加宠物
public void addPet(){
System.out.println("请输入宠物昵称");
String name = input.next();
System.out.println("请输入宠物健康值");
int health = input.nextInt();
System.out.println("请输入宠物亲密度");
int love = input.nextInt();
System.out.println("请选择宠物类别(1.狗狗类 2.企鹅类)");
int type = input.nextInt();
String pStr="";
switch (type) {
case 1:
System.out.println("请输入狗狗的品种");
pStr =input.next();
Dog dog = new Dog(name ,health,love,pStr);
list.add(dog);
break;
case 2:
System.out.println("请输入企鹅的性别");
pStr =input.next();
Penguin pen = new Penguin(name,health,love,pStr);
list.add(pen);
break;
}
}
//5.修改宠物信息
public void xiugai() {
}
//6.删除宠物
public void deletePet(){
System.out.println("请输入要删除的宠物昵称");
String name = input.next();
for (Pet pet : list) {
if(name.equals(pet.getName())){
//从集合中删除宠物
list.remove(pet);
System.out.println("删除成功");
break;
}
}
}