宠物管理系统 宠物寄养技术实现 代码示例
时间: 2023-11-30 16:53:35 浏览: 116
基于 SpringBoot+Vue+MySQL实现的宠物管理系统源代码
这是一个简单的宠物寄养管理系统的代码示例,包括了宠物信息的录入、查询和删除功能,以及寄养信息的录入和查询功能。
```python
class Pet:
def __init__(self, name, species, age, owner):
self.name = name
self.species = species
self.age = age
self.owner = owner
class Boarding:
def __init__(self, pet, start_date, end_date):
self.pet = pet
self.start_date = start_date
self.end_date = end_date
class PetManagement:
def __init__(self):
self.pets = []
self.boardings = []
def add_pet(self, pet):
self.pets.append(pet)
def remove_pet(self, name):
for pet in self.pets:
if pet.name == name:
self.pets.remove(pet)
def find_pet(self, name):
for pet in self.pets:
if pet.name == name:
return pet
return None
def add_boarding(self, boarding):
self.boardings.append(boarding)
def find_boarding(self, name):
for boarding in self.boardings:
if boarding.pet.name == name:
return boarding
return None
```
这里定义了三个类,分别是宠物类 `Pet`、寄养类 `Boarding` 和宠物管理类 `PetManagement`。宠物类用于存储宠物的基本信息,寄养类用于存储宠物的寄养信息,宠物管理类用于管理宠物和寄养信息。
下面是一个简单的使用示例:
```python
pm = PetManagement()
# 添加宠物
pet1 = Pet("小白", "狗", 2, "张三")
pet2 = Pet("小黄", "猫", 1, "李四")
pm.add_pet(pet1)
pm.add_pet(pet2)
# 查询宠物
pet = pm.find_pet("小白")
if pet:
print("宠物名:", pet.name)
print("宠物种类:", pet.species)
print("宠物年龄:", pet.age)
print("宠物主人:", pet.owner)
# 删除宠物
pm.remove_pet("小黄")
# 添加寄养信息
boarding1 = Boarding(pet1, "2022-01-01", "2022-01-10")
pm.add_boarding(boarding1)
# 查询寄养信息
boarding = pm.find_boarding("小白")
if boarding:
print("宠物名:", boarding.pet.name)
print("寄养开始日期:", boarding.start_date)
print("寄养结束日期:", boarding.end_date)
```
阅读全文