当前位置: 首页 > article >正文

宠物管理系统(1):Bean设计

        byd学校期末搞实训,做一个宠物管理系统,没有数据库,纯靠文件存储数据,并且还要保证数据的一致性,十分麻烦,但是还是做出来了。先介绍一下系统中bean的设计:

        User类

package com.wzb.bean;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;

public class User implements Serializable {
    // id作为用户的唯一标识符
    private final Integer id;
    // 用户名
    private final String username;
    // 密码
    private String password;
    // 手机号
    private String phoneNumber;
    // 用户的账户余额
    private Integer money;
    // 用户的地址
    private String address;
    // 用户状态
    private Boolean status;
    // 用户持有的宠物
    private ArrayList<Integer> petList;
    // 用户的购物车
    private ArrayList<Integer> shopCar;
    // 用户的订单表
    private ArrayList<Order> orderList;
    // 注册时间
    private LocalDate registerDate;
    // 修改时间
    private LocalDateTime updateTime;


    // 用户注册凭证:手机号注册
    public User(Integer id, String username, String password, String phoneNumber) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.phoneNumber = phoneNumber;

        // 用户账户默认没钱
        this.money = 0;
        // 用户状态默认可用
        this.status = true;
        // 用户默认无宠物
        this.petList = new ArrayList<>();
        // 用户购物车
        this.shopCar = new ArrayList<>();
        // 用户订单表
        this.orderList = new ArrayList<>();
        // 注册时间
        this.registerDate = LocalDate.now();
        // 修改时间
        this.updateTime = LocalDateTime.now();
    }

    // 创建管理员用户
    public User(Integer id, String username, String password, String phoneNumber, int money) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.phoneNumber = phoneNumber;
        this.money = money;
        this.address = "重庆文理学院wzb";

        this.status = true;
        this.petList = new ArrayList<>();
        petList.add(0);
        // 用户购物车
        this.shopCar = new ArrayList<>();
        // 用户订单表
        this.orderList = new ArrayList<>();
        // 注册时间
        this.registerDate = LocalDate.now();
        // 修改时间
        this.updateTime = LocalDateTime.now();
    }

    public Integer getId() {
        return id;
    }

    public String getUsername() {
        return username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getMoney() {
        return money;
    }

    public void setMoney(Integer money) {
        this.money = money;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Boolean getStatus() {
        return status;
    }

    public void setStatus(Boolean status) {
        this.status = status;
    }

    public ArrayList<Integer> getPetList() {
        return petList;
    }

    public void setPetList(ArrayList<Integer> petList) {
        this.petList = petList;
    }

    public ArrayList<Integer> getShopCar() {
        return shopCar;
    }

    public void setShopCar(ArrayList<Integer> shopCar) {
        this.shopCar = shopCar;
    }

    public ArrayList<Order> getOrderList() {
        return orderList;
    }

    public void setOrderList(ArrayList<Order> orderList) {
        this.orderList = orderList;
    }

    public LocalDate getRegisterDate() {
        return registerDate;
    }

    public void setRegisterDate(LocalDate registerDate) {
        this.registerDate = registerDate;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public void addMoney(Integer money) {
        this.money += money;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", phoneNumber='" + phoneNumber + '\'' +
                ", money=" + money +
                ", address='" + address + '\'' +
                ", status=" + status +
                ", petList=" + petList +
                ", shopCar=" + shopCar +
                ", orderList=" + orderList +
                ", registerDate=" + registerDate +
                ", updateTime=" + updateTime +
                '}';
    }

    public void showOrders() {
        System.out.println("当前用户" + username + "的订单内容为");
        for (int i = 0; i < orderList.size(); i++) {
            System.out.println("这是第" + (i + 1) + "张订单");
            System.out.println(orderList.get(i));
        }
    }

}

        Pet类

package com.wzb.bean;

import java.io.Serializable;

public class Pet implements Serializable {
    private final Integer id;
    private String name;
    private Integer age;
    private Double weight;
    private String food;
    private Integer price;
    private Integer brand;

    // 通过构造器传入 ID,而不是通过静态初始化获取
    public Pet(Integer id, String name, Integer age, Double weight, String food, Integer price, Integer brand) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.weight = weight;
        this.food = food;
        this.price = price;
        this.brand = brand;
    }

    // Getter 和 Setter 方法
    public Integer getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Double getWeight() {
        return weight;
    }

    public void setWeight(Double weight) {
        this.weight = weight;
    }

    public String getFood() {
        return food;
    }

    public void setFood(String food) {
        this.food = food;
    }

    public Integer getPrice() {
        return price;
    }

    public void setPrice(Integer price) {
        this.price = price;
    }

    public Integer getBrand() {
        return brand;
    }

    public void setBrand(Integer brand) {
        this.brand = brand;
    }

    @Override
    public String toString() {
        return "Pet{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", weight=" + weight +
                ", food='" + food + '\'' +
                ", price=" + price +
                '}';
    }
}

        Order类

package com.wzb.bean;

import com.wzb.service.PetService;
import com.wzb.service.impl.PetServiceImpl;

import java.io.Serializable;
import java.util.ArrayList;

public class Order implements Serializable {
    private static final PetService petService = new PetServiceImpl();

    private final ArrayList<Integer> pets;
    private final Integer sum;

    public Order(ArrayList<Integer> pets, Integer sum) {
        this.pets = pets;
        this.sum = sum;
    }

    public ArrayList<Integer> getPets() {
        return pets;
    }

    @Override
    public String toString() {
        String result = "{Order: Pets{";
        for (Integer id : pets) {
            result = result + "{";
            result += petService.getById(id);
            result += "}";
        }
        result += "}, ";
        result += "Sum{" + sum + "}}";
        return result;
    }
}

        Cat类和Dog类

package com.wzb.bean;

public class Cat extends Pet{

    public Cat(Integer id, String name, Integer age, Double weight, String food, Integer price, Integer brand) {
        super(id, name, age, weight, food, price, brand);
    }

    public void catchMouse() {
        System.out.println("小猫" + this.getName() + "能够抓老鼠");
    }
}
package com.wzb.bean;

public class Dog extends Pet{
    public Dog(Integer id, String name, Integer age, Double weight, String food, Integer price, Integer brand) {
        super(id, name, age, weight, food, price, brand);
    }

    public void fight() {
        System.out.println("小狗" + this.getName() + "能够看家");
    }
}

 

 

 

 


http://www.kler.cn/a/446700.html

相关文章:

  • STM32-笔记5-按键点灯(中断方法)
  • 20241217使用M6000显卡在WIN10下跑whisper来识别中英文字幕
  • imx6ull qt多页面控制系统(正点原子imx系列驱动开发)
  • C语言进阶(2) ---- 指针的进阶
  • Mac系统Android sdk的安装
  • Ubuntu下C语言操作kafka示例
  • EMMC , UFS, SSD介绍
  • 如何解决vscode powershell乱码
  • 解决PCL库中pcl::VoxelGrid降采样Bug
  • 鸿蒙项目云捐助第十三讲大模型进行智能问答应用进阶
  • 异步BUCK二极管损耗计算
  • 时空信息平台-API安全措施:上篇(通讯协议的安全措施)
  • 工泰“安全有序·消防护盾”统建统服有序充电新产品发布会成功举办
  • Dubbo 3.x源码(27)—Dubbo服务引用源码(10)subscribeURLs订阅应用级服务url
  • 如何在谷歌浏览器中设置家庭安全
  • harmonyOS组件拥有的状态汇总
  • SpringBoot 3.4.x踩坑记录及解决方案(持续更新)
  • K8s ConfigMap的基础功能介绍
  • 第十五届蓝桥杯Scratch01月stema选拔赛—排序
  • linux-----数据库
  • 机器学习架起了组学科学和植物育种之间的桥梁。
  • 若依启动项目时配置为 HTTPS 协议
  • Redis中的Hot key排查和解决思路
  • B树的性质和插入过程
  • 入侵他人电脑,实现远程控制(待补充)
  • 怿星科技联合赛力斯举办workshop活动,进一步推动双方合作