首页 > 分享 > 主人领养宠物(Java与sqlserver连接的案例)资源

主人领养宠物(Java与sqlserver连接的案例)资源

package Biz; import java.util.Scanner; import dao.BuyPet; import dao.MasterDao; import dao.MasterImpl; import dao.PetDao; import dao.PetDaoImpl; import entity.Master; import entity.Pet; public class MasterManage {private Master master = null;private PetManage petManage = new PetManage();public void Login() {Scanner input = new Scanner(System.in);System.out.println("欢迎光临,请进行登入:");System.out.println("输入登入名:");String name = input.next();System.out.println("输入密码:");String password = input.next();Master mas = new Master();mas.setName(name);mas.setPassWord(password);MasterDao masterDao = new MasterImpl();master = masterDao.findMaster(mas);if (master == null) {System.out.println("登入失败");} else {System.out.println("登入成功,现在可以领养宠物");buyMain();}}public void buyMain() {System.out.println("***********************************************");System.out.println("1.领养宠物t2.放弃领养宠物");System.out.println("***********************************************");Scanner input = new Scanner(System.in);int choice = input.nextInt();if (choice == 1) {buyPet();} else if (choice == 2) {overPet();} else {System.out.println("输入有误");}}public void buyPet() {Scanner input = new Scanner(System.in);System.out.println("查找宠物*******************************");petManage.findPet();System.out.println("输入需要领养的宠物名,输入n结束此操作");String name = input.next();if (!name.equals("n")) {PetDao petDao = new PetDaoImpl();Pet pet = petDao.getByName(name);if (pet == null) {System.out.println("无该宠物");} else if (pet.getStatus().equals("已被领养")) {System.out.println("该宠物已被领养");} else if (pet.getPrice() > master.getMoney()) {System.out.println("该宠物的价格为" + pet.getPrice() + ",你的剩余资金为" + master.getMoney() + ",资金不足");} else {BuyPet buyPet = new BuyPet();PetDao petDao1 = new PetDaoImpl();System.out.println("输入购买的宠物时间:yyyy-mm-dd");String date = input.next();pet.setAdoptTime(date);pet.setMasterId(master.getId());pet.setStatus("已被领养");MasterDao masterDao = new MasterImpl();petDao1.upDate(pet);int money = master.getMoney() - pet.getPrice();master.setMoney(money);masterDao.upDate(master);buyPet.adoptPet(master.getName(), pet.getName());System.out.println("领养成功");}}}public void overPet() {Scanner input = new Scanner(System.in);BuyPet buypet = new BuyPet();boolean ready = buypet.showBuypet(master.getName());if (ready) {System.out.println("选择要放弃领养的宠物名");String name = input.next();int result = buypet.delBuy(name);if (result == 1) {System.out.println("放弃领养成功");} else {System.out.println("放弃领养失败");}} else {System.out.println("你还没有领养宠物");}System.out.println("输入1开始领养宠物");int choice=input.nextInt();if(choice==1){buyPet();}}public void masterMain() {showMaster();Scanner input = new Scanner(System.in);System.out.println("***********************************************");System.out.println("1.增加主人t2.删除主人t3.修改主人t4.查找主人");System.out.println("***********************************************");int choice = input.nextInt();switch (choice) {case 1:addMaster();showMaster();break;case 2:delMaster();showMaster();break;case 3:updateMaster();showMaster();break;case 4:findMa();break;default:System.out.println("输入错误");}}public void showMaster() {// 显示主人信息MasterImpl masterImpl = new MasterImpl();masterImpl.showAllMaster();}public void addMaster() {// 增加主人MasterDao masterDao = new MasterImpl();Scanner input = new Scanner(System.in);Master master = new Master();System.out.println("输入主人名");String name = input.next();if(masterDao.findMaster(name)!=null){System.out.println("有相同的主人名,请重新输入");}else{master.setName(name);System.out.println("输入主人密码");String pass = input.next();master.setPassWord(pass);System.out.println("输入主人的钱数");int money = input.nextInt();master.setMoney(money);int result = masterDao.save(master);if (result == 1) {System.out.println("添加成功");} else {System.out.println("添加失败");}}}public void delMaster() {// 删除主人MasterDao masterDao = new MasterImpl();Scanner input = new Scanner(System.in);Master master = new Master();System.out.println("输入要删除的主人的id");int masterId = input.nextInt();master.setId(masterId);int result = masterDao.del(master);if (result == 1) {System.out.println("删除成功");} else {System.out.println("删除失败");}}public void updateMaster() {// 修改主人信息MasterDao masterDao = new MasterImpl();Scanner input = new Scanner(System.in);Master master = null;System.out.println("输入需要修改信息的的主人名");String name = input.next();master = masterDao.findMaster(name);System.out.println("输入新的密码");String pass = input.next();master.setPassWord(pass);System.out.println("输入新的钱数");int money = input.nextInt();master.setMoney(money);int result = masterDao.upDate(master);if (result == 1) {System.out.println("更新成功");} else {System.out.println("更新失败");}}public void findMa() {// 通过名字查找主人MasterDao masterDao = new MasterImpl();Scanner input = new Scanner(System.in);Master newMaster = null;System.out.println("输入主人名");String name = input.next();newMaster = masterDao.findMaster(name);if (newMaster == null) {System.out.println("查无此主人");} else {System.out.println("主人idtt主人名tt主人密码tt主人持有的钱");System.out.print(newMaster.getId() + "tt");System.out.print(newMaster.getName() + "tt");System.out.print(newMaster.getPassWord() + "tt");System.out.println(newMaster.getMoney());}} }

相关知识

案例27:基于Java宠物领养系统开题报告设计
毕业设计:基于java的宠物领养系统设计与实现
Java计算机毕业设计的宠物领养系统(开题报告+源码+论文)
基于java的宠物用品店系统的设计与实现
【2024】基于springboot的宠物领养管理系统设计与实现
【开题报告】基于java的流浪之家动物领养网站的设计与开发
宠物用品在线交易系统(chongwuyongpin),基于java的毕业设计
SSM宠物领养系统:Java项目实战
java计算机毕业设计宠物领养系统(开题+程序+论文)
java宠物领养网站毕业设计答辩PPT.pptx

网址: 主人领养宠物(Java与sqlserver连接的案例)资源 https://m.mcbbbk.com/newsview405765.html

所属分类:萌宠日常
上一篇: 善待动物的真实事例
下一篇: 事实收养案例