/**
*
*/
package cn.jbit.epetShop.test;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import cn.jbit.epetShop.dao.PetDao;
import cn.jbit.epetShop.dao.PetOwnerDao;
import cn.jbit.epetShop.dao.PetStoreDao;
import cn.jbit.epetShop.dao.impl.PetDaoImpl;
import cn.jbit.epetShop.dao.impl.PetOwnerDaoImpl;
import cn.jbit.epetShop.dao.impl.PetStoreDaoImpl;
import cn.jbit.epetShop.entity.Account;
import cn.jbit.epetShop.entity.Pet;
import cn.jbit.epetShop.entity.PetOwner;
import cn.jbit.epetShop.entity.PetStore;
import cn.jbit.epetShop.model.PetOwnerService;
import cn.jbit.epetShop.model.PetStoreService;
import cn.jbit.epetShop.model.PetStoreFactory;
import cn.jbit.epetShop.model.impl.PetOwnerServiceImpl;
import cn.jbit.epetShop.model.impl.PetStoreFactoryImpl;
import cn.jbit.epetShop.model.impl.PetStoreServiceImpl;
/**
* @author 北大青鸟 入口类
*
*/
public class Main {
/**
* @param args
* void 系统入口方法
*/
public static void main(String[] args) {
Main.startPetShop();
}
/**
* 系统启动
*/
public static void startPetShop() {
System.out.println(" 宠物商店启动");
System.out.println("Wonderland醒来,所有宠物从oracle中醒来");
System.out
.println("****************************************************");
PetDao petDao = new PetDaoImpl();
List<Pet> petList = petDao.getAllPet();
for (int i = 0; i < petList.size(); i++) {
Pet pet = petList.get(i);
System.out.println("第" + (i + 1) + "个宠物,名字叫:" + pet.getName());
}
System.out
.println("****************************************************");
System.out.print("\n");
System.out.println("所有宠物主人从oracle中醒来");
PetOwnerDao ownerDao = new PetOwnerDaoImpl();
List<PetOwner> ownerList = ownerDao.getAllOwner();
System.out
.println("****************************************************");
for (int i = 0; i < ownerList.size(); i++) {
PetOwner owner = ownerList.get(i);
System.out.println("第" + (i + 1) + "个宠物主人,名字叫:" + owner.getName());
}
System.out
.println("****************************************************");
System.out.print("\n");
System.out.println("所有宠物商店从oracle中醒来");
System.out
.println("****************************************************");
PetStoreDao storeDao = new PetStoreDaoImpl();
List<PetStore> storeList = storeDao.getAllStore();
for (PetStore store : storeList) {
System.out.println("我的名字叫:" + store.getName());
}
System.out
.println("****************************************************");
System.out.print("\n");
Scanner input = new Scanner(System.in);
System.out.println("请选择输入登录模式,输入1为宠物主人登录,输入2为宠物商店登录");
boolean type = true;
String num;
while (type) {
num = input.next();
if ("1".equals(num)) {
Main.ownerLogin();
type = false;
} else if ("2".equals(num)) {
Main.storeLogin();
type = false;
} else {
System.out.println("输入有误,请按照指定规则输入");
System.out.println("请选择登录模式,输入1为宠物主人登录,输入2为宠物商店登录");
type = true;
}
}
}
/**
* 宠物主人登录方法
*/
public static PetOwner ownerLogin() {
Scanner input = new Scanner(System.in);
PetOwnerServiceImpl petOwner = new PetOwnerServiceImpl();
PetOwner Owner = petOwner.login();
boolean reg = true;
while (reg) {
if (null == Owner) {
System.out.println("登录失败,请确认您的用户名和密码后重新输入");
Owner = petOwner.login();
reg = true;
} else {
reg = false;
System.out.println("登录成功,您可以购买和卖出宠物,如果您想购买宠物请输入1,如果想卖出宠物请输入2");
System.out.println("1:购买宠物");
System.out.println("2:卖出宠物");
boolean type = true;
while (type) {
int num = input.nextInt();
if (1 == num) {
Main.ownerBuy(Owner);
type = false;
} else if (2 == num) {
Main.ownerSell(Owner);
type = false;
} else {
System.out.println("输入有误,请重新输入");
type = true;
}
}
}
}
return Owner;
}
/**
* 宠物商店登录方法
*/
public static PetStore storeLogin() {
Scanner input = new Scanner(System.in);
PetStoreService petStore = new PetStoreServiceImpl();
PetStore store = petStore.login();
System.out.println("登录成功,可以进行如下操作");
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("请根据需要执行的操作,选择序号输入,退出请输入0");
boolean type = true;
while (type) {
int num = input.nextInt();
switch (num) {
case 0:
System.out.println("退出成功");
type = false;
break;
case 1:
Main.storeBuy(store);
type = false;
break;
case 2:
Main.storeSell(store);
type = false;
break;
case 3:
Main.storeBread();
type = false;
break;
case 4:
Main.queryPetStock(store.getId());
type = false;
break;
case 5:
Main.queryStoreBalance(store);
type = false;
break;
case 6:
Main.getAccount(store.getId());
type = false;
break;
case 7:
Main.createPetStore();
type = false;
break;
default:
System.out.println("输入有误,请重新输入");
type = true;
break;
}
}
return store;
}
/**
* 查询商店结余
*/
public static void queryStoreBalance(PetStore petStore) {
double balance = petStore.getBalance();
System.out.println(petStore.getName() + "宠物商店的结余为:" + balance);
}
/**
* 查询待售宠物
*/
public static void queryPetStock(long storeId) {
PetStoreService petStore = new PetStoreServiceImpl();
Pet pet = null;
List<Pet> petList = petStore.getPetsInstock(storeId);
for (int i = 0; i < petList.size(); i++) {
pet = petList.get(i);
System.out.println("序号:" + (i + 1) + "我的名字叫:" + pet.getName()
+ " 我是:" + pet.getTypeName());
}
}
/**
* 宠物商店购买宠物
*/
public static void storeBuy(PetStore store) {
Scanner input = new Scanner(System.in);
PetStoreService petStore = new PetStoreServiceImpl();
Pet pet = null;
List<Pet> petList = petStore.getPetSelling();
System.out.println("-------以下是宠物主人正在出售的宠物-------");
for (int i = 0; i < petList.size(); i++) {
pet = petList.get(i);
double price = petStore.charge(pet);// 获得到宠物的价格
System.out.println("序号:" + (i + 1) + "我的名字叫:" + pet.getName()
+ " 我是:" + pet.getTypeName() + "要购买我要花:" + price + "个元宝");
}
System.out.println("-------请选择要购买哪个一个宠物,并输入选择项的序号-------");
int num = input.nextInt();
pet = petList.get(num - 1);
petStore.buy(pet);
}
/**
* 宠物商店出售宠物
*/
public static void storeSell(PetStore store) {
Scanner input = new Scanner(System.in);
PetStoreService petStore = new PetStoreServiceImpl();
Pet pet = null;
List<Pet> petList = petStore.getPetsInstock(store.getId());
System.out.println("-------以下是宠物商店正在出售的宠物-------");
for (int i = 0; i < petList.size(); i++) {
pet = petList.get(i);
System.out.println("序号:" + (i + 1) + "我的名字叫:" + pet.getName()
+ " 我是:" + pet.getTypeName());
}
System.out.println("---------请选择要购买的宠物序号--------");
boolean type = true;
while (type) {
int num = input.nextInt();
if ((num - 1) < petList.size() && (num - 1) >= 0) {
pet = petList.get(num - 1);
System.out.println("------要卖出的宠物信息如下------");
System.out.println("宠物名字叫:" + pet.getName() + " 宠物类别是:"
+ pet.getTy