The Change Count Machine is a Python application that calculates the optimal denomination breakdown for a given monetary amount. It includes a GUI built using Tkinter for user interaction.
- Calculates the minimum number of denominations for any given amount.
- Displays a detailed breakdown of the denominations used.
- Saves results to SQL database that can be viewed later.
- Ability to clear database of previously saved calculations.
- User-friendly interface for entering the amount and viewing results.
- Purpose: Contains the core functionality for calculating the denomination breakdown.
- Key Functions:
- `denominations_calc(money_left, dom)': Determines how many of a specific denomination can be used for the given amount.
- `compute_loop(money_left,denom_list,denom_counts,total_items)': Iteratively calculates the optimal denomination breakdown for the input amount.
- `compute_change(money)': Holds the list of denominations, call "compute_loop" to preform it's loop, and returns results to the requester.
- Purpose: Provides a graphical user interface for interacting with the Change Count Machine.
- Features:
- Entry field for inputting the amount.
- Button to trigger the calculation.
- Button to trigger the display for previous results.
- Button to trigger clearing of SQL database.
- Display area for showing the results.
- Purpose: Contains the functionality for the SQL database
- Features:
- `create_db(cursor)': Creates the SQL table.
- `check_and_create_db()': Checks if the SQL database already exists and if not call "create_db".
- `insert_calculation(conn, cursor, amount, total_items, denom_counts)': Inserts a calculation from "change_count_machine.py" into the SQL database.
- `def get_all_calculations(cursor)': Gathers all of the calculations in the SQL database and returns them.
- `def clear_calculations(conn, cursor)': Clears the SQL database of previously saved calculations.
- Python 3.x
- Tkinter (included in most Python installations)
- SQLite
- Clone or download the repository.
- Ensure you have Python installed on your system.
- No additional libraries are required.
- Run the GUI:
- Make sure that the last line in `gui.py' is uncommented:
create_gui()[0].mainloop()
- Execute the script:
python gui.py
- Make sure that the last line in `gui.py' is uncommented:
- Enter the desired monetary amount in the input field.
- Click "Calculate" to view the denomination breakdown.
- Click "View History" to view saved calculations.
- Click "Clear" to clear saved calculations (will need to confirm your choice).
- Amount: '123.45'
- Total items: 9
- Denomination breakdown: $100.00: 1, $20.00: 1, $1.00: 3, $0.25: 1, $0.10: 2
- The denomination list can be adjusted in 'change_count_machine.py' to include additional values, e.g., '$2' or '$0.50`.
- Input validation ensures that only positive numeric values are accepted.
- The GUI components ( 'root', 'entry', 'calculate_button', 'result_label') are returned for unit testing in 'create_gui()'.
- To run tests either use "pytest" for all tests or "pytest test_file_name".
- To run tests either be in the "root" directory or "tests" directory (tests will not run as stated inside the "src" directory).
- Comment 'create_gui()[0].mainloop()' when running all tests or tests with 'test_gui.py'.