This project intends to build an expense tracker using python object-oriented programming concepts.
In this project we created two classes: "Expense" and "ExpenseDatabase"
Have methods such as __init__, update and to_dict.Methods:
init(self, title, amount): Initializes an Expense object with a unique ID, title, amount, creation time, and update time.
update(self, title=None, amount=None): Updates the title and/or amount of the expense and modifies the updated_at timestamp accordingly.
to_dict(self): Converts the expense object into a dictionary format for easy serialization.
Have methods such as init, add_expense, remove_expense, get_expense_by_id, get expense_by_title, to_dict
Methods:
init(self): Initializes an empty list to store expenses.
add_expense(self, expense): Adds a new expense object to the database.
remove_expense(self, expense_id): Removes an expense from the database by its ID.
get_expense_by_id(self, expense_id): Retrieves an expense by its ID.
get_expense_by_title(self, expense_title): Retrieves a list of expenses with a given title.
to_dict(self): Converts the list of expenses into a dictionary format for easy serialization.
The ExpenseDatabase class manages a list of expenses, allowing addition, removal, and retrieval based on ID or title.
The code uses UUID for unique identification, datetime for timestamp management, and dictionary formats for easy conversion and serialization.
In Github, we clone the repository by using the git clone. The git clone command is used to create a copy of a specific repository or branch within a repository.
Git is a distributed version control system. Maximize the advantages of a full repository on your own machine by cloning.
The steps to Initiation a git clone.1. Create a folder in the local machine to clone your remote repository into by using the keyword in windows "mkdir {directory-name}", after initially setting your terminal to the right directory using the "cd {directory-name}."
Any of the terminal on your system can be used for handling git provided it is already installed on your system. Be it Powershell, CommandPrompt, Git Bash, VS Code and even Git GUI.
2. Cloning the git repository into the folder created using the
git clone https://github.com/oakerekan/altschool-first-semester.git/
When you clone a repository, you don't get one file, like you may in other centralized version control systems. By cloning with Git, you get the entire repository - all files, all branches, and all commits.
Cloning a repository is typically only done once, at the beginning of your interaction with a project. Once a repository already exists on a remote, like on GitHub, then you would clone that repository so you could interact with it locally. Once you have cloned a repository, you won't need to clone it again to do regular development.
The ability to work with the entire repository means that all developers can work more freely. Without being limited by which files you can work on, you can work on a feature branch to make changes safely.
The provided code is a script to demonstrate the functionality of an expense tracking system using the Expense and ExpenseDatabase classes. Breaking it down in bits to help explain the implementation.
expense_1 = Expense(title="fuel", amount=10000)
expense_2 = Expense(title="transport", amount=2000)
expense_3 = Expense(title="data", amount=1000)
expense_4 = Expense(title="food", amount=3000)
expense_5 = Expense(title="shoes", amount=10000)
expense_6 = Expense(title="shoes", amount=300000)
edb = ExpenseDatabase()
for expense in [expense_1, expense_2, expense_3, expense_4, expense_5, expense_6]:
edb.add_expense(expense)
print(edb.expenses)
print()
print("-" * 30)
print()
This part of the code adds each expense to the ExpenseDatabase and prints the database after each addition.
print(expense_1.update(title="food", amount=5000))
This part of the code updates expense_1 with a new title ("food") and amount (5000)
print(edb.remove_expense(expense_id=expense_2.id))
This part of the code removes the expense with expense_2's ID from the ExpenseDatabase.
print(edb.get_expense_by_id(expense_id=expense_1.id))
print(edb.get_expense_by_title(expense_title="shoes"))
These lines fetch an expense by its ID and title from the ExpenseDatabase.
print(edb.to_dict())
This part of the code prints the ExpenseDatabase converted to a dictionary of dictionaries.
Note: The to_dict method is likely designed to convert the ExpenseDatabase contents into a dict of dictionaries for easy representation or serialization.
Overall, the code provides a basic illustration of expense management functionalities using the defined classes.