家庭财务管理系统毕设
时间: 2024-06-14 08:06:41 浏览: 70
家庭财务管理系统是一个非常适合毕设的主题,它可以帮助人们更好地管理家庭的财务情况。下面是一个简单的家庭财务管理系统的示例:
```python
class Expense:
def __init__(self, category, amount):
self.category = category
self.amount = amount
class Income:
def __init__(self, source, amount):
self.source = source
self.amount = amount
class FamilyFinance:
def __init__(self):
self.expenses = []
self.incomes = []
def add_expense(self, category, amount):
expense = Expense(category, amount)
self.expenses.append(expense)
def add_income(self, source, amount):
income = Income(source, amount)
self.incomes.append(income)
def calculate_total_expenses(self):
total_expenses = 0
for expense in self.expenses:
total_expenses += expense.amount
return total_expenses
def calculate_total_incomes(self):
total_incomes = 0
for income in self.incomes:
total_incomes += income.amount
return total_incomes
def calculate_net_profit(self):
total_incomes = self.calculate_total_incomes()
total_expenses = self.calculate_total_expenses()
net_profit = total_incomes - total_expenses
return net_profit
# 示例用法
finance = FamilyFinance()
finance.add_expense("食品", 1000)
finance.add_expense("交通", 500)
finance.add_income("工资", 5000)
finance.add_income("股票收益", 2000)
total_expenses = finance.calculate_total_expenses()
total_incomes = finance.calculate_total_incomes()
net_profit = finance.calculate_net_profit()
print("总支出:", total_expenses)
print("总收入:", total_incomes)
print("净利润:", net_profit)
```
这个示例中,我们定义了三个类:`Expense`(支出)、`Income`(收入)和`FamilyFinance`(家庭财务)。`Expense`和`Income`类分别表示一笔支出和一笔收入,它们都有一个类别(category/source)和金额(amount)。`FamilyFinance`类用于管理家庭的财务情况,它可以添加支出和收入,并计算总支出、总收入和净利润。
阅读全文