用java做一个花店管理系统
时间: 2023-08-24 18:05:22 浏览: 122
java+花店管理
好的,下面是一个简单的花店管理系统的Java实现,包括基本的花卉信息管理、库存管理、销售管理和财务管理等功能:
1. 首先,我们定义一个花卉类,用于存储花卉的基本信息,如名称、价格、库存等:
```java
public class Flower {
private String name; // 花卉名称
private double price; // 花卉单价
private int stock; // 花卉库存
public Flower(String name, double price, int stock) {
this.name = name;
this.price = price;
this.stock = stock;
}
// getter and setter methods
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getStock() {
return stock;
}
public void setStock(int stock) {
this.stock = stock;
}
}
```
2. 接下来,我们定义一个花卉管理类,用于实现花卉信息的添加、修改、删除和查询等操作:
```java
import java.util.ArrayList;
public class FlowerManager {
private ArrayList<Flower> flowerList; // 花卉列表
public FlowerManager() {
flowerList = new ArrayList<Flower>();
}
// 添加花卉
public void addFlower(Flower flower) {
flowerList.add(flower);
}
// 修改花卉信息
public void updateFlower(String name, double price, int stock) {
for (Flower flower : flowerList) {
if (flower.getName().equals(name)) {
flower.setPrice(price);
flower.setStock(stock);
break;
}
}
}
// 删除花卉
public void deleteFlower(String name) {
for (Flower flower : flowerList) {
if (flower.getName().equals(name)) {
flowerList.remove(flower);
break;
}
}
}
// 查询花卉信息
public Flower getFlower(String name) {
for (Flower flower : flowerList) {
if (flower.getName().equals(name)) {
return flower;
}
}
return null;
}
}
```
3. 然后,我们定义一个库存管理类,用于实现库存的增加和减少等操作:
```java
public class StockManager {
private FlowerManager flowerManager; // 花卉管理类
public StockManager(FlowerManager flowerManager) {
this.flowerManager = flowerManager;
}
// 增加库存
public void addStock(String name, int amount) {
Flower flower = flowerManager.getFlower(name);
if (flower != null) {
flower.setStock(flower.getStock() + amount);
}
}
// 减少库存
public void reduceStock(String name, int amount) {
Flower flower = flowerManager.getFlower(name);
if (flower != null) {
flower.setStock(flower.getStock() - amount);
}
}
}
```
4. 接着,我们定义一个销售管理类,用于实现销售记录的添加和查询等操作:
```java
import java.util.ArrayList;
import java.util.Date;
public class SalesManager {
private ArrayList<SalesRecord> salesRecordList; // 销售记录列表
public SalesManager() {
salesRecordList = new ArrayList<SalesRecord>();
}
// 添加销售记录
public void addSalesRecord(String name, int amount) {
Flower flower = flowerManager.getFlower(name);
if (flower != null && flower.getStock() >= amount) {
double price = flower.getPrice();
double totalPrice = price * amount;
Date date = new Date();
SalesRecord record = new SalesRecord(name, amount, price, totalPrice, date);
salesRecordList.add(record);
flower.setStock(flower.getStock() - amount);
}
}
// 查询销售记录
public ArrayList<SalesRecord> getSalesRecord(Date startDate, Date endDate) {
ArrayList<SalesRecord> result = new ArrayList<SalesRecord>();
for (SalesRecord record : salesRecordList) {
if (record.getDate().after(startDate) && record.getDate().before(endDate)) {
result.add(record);
}
}
return result;
}
// 销售记录类
private class SalesRecord {
private String name; // 花卉名称
private int amount; // 销售数量
private double price; // 花卉单价
private double totalPrice; // 总价
private Date date; // 销售日期
public SalesRecord(String name, int amount, double price, double totalPrice, Date date) {
this.name = name;
this.amount = amount;
this.price = price;
this.totalPrice = totalPrice;
this.date = date;
}
// getter and setter methods
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public double getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(double totalPrice) {
this.totalPrice = totalPrice;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}
}
```
5. 最后,我们定义一个财务管理类,用于实现销售收入和花费的统计等操作:
```java
import java.util.ArrayList;
import java.util.Date;
public class FinanceManager {
private SalesManager salesManager; // 销售管理类
private ArrayList<Expense> expenseList; // 花费列表
public FinanceManager(SalesManager salesManager) {
this.salesManager = salesManager;
expenseList = new ArrayList<Expense>();
}
// 添加花费
public void addExpense(String name, double amount, Date date) {
Expense expense = new Expense(name, amount, date);
expenseList.add(expense);
}
// 获取销售收入
public double getSalesIncome(Date startDate, Date endDate) {
ArrayList<SalesManager.SalesRecord> records = salesManager.getSalesRecord(startDate, endDate);
double income = 0;
for (SalesManager.SalesRecord record : records) {
income += record.getTotalPrice();
}
return income;
}
// 获取花费总额
public double getExpenseTotal(Date startDate, Date endDate) {
double total = 0;
for (Expense expense : expenseList) {
if (expense.getDate().after(startDate) && expense.getDate().before(endDate)) {
total += expense.getAmount();
}
}
return total;
}
// 获取利润
public double getProfit(Date startDate, Date endDate) {
return getSalesIncome(startDate, endDate) - getExpenseTotal(startDate, endDate);
}
// 花费类
private class Expense {
private String name; // 花费名称
private double amount; // 花费金额
private Date date; // 花费日期
public Expense(String name, double amount, Date date) {
this.name = name;
this.amount = amount;
this.date = date;
}
// getter and setter methods
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}
}
```
以上是一个简单的花店管理系统的Java实现,你可以根据自己的需求进行修改和完善。
阅读全文